项目组实际线上服务器配的nginx配置:
#工作进程数
worker_processes 1;
#错误日志存放路径
#error_log /var/log/nginx/error.log warn;
#进程标识符存放路径
#pid /tmp/nginx.pid;
events {
#每个进程的最大连接数量
worker_connections 1024;
}
#设定http服务器,利用其反向代理提供负载均衡支持
http {
#设定mime类型,由mime.types文件定义
#include /etc/nginx/mime.types;
default_type application/octet-stream;
#日志格式设置
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#指定日志存放路径
#access_log /var/log/nginx/access.log main;
#指定nginx是否调用sendfile函数来输出文件
sendfile on;
#是否允许socket的TCP_CORK的选项,仅在使用sendfile时使用
#tcp_nopush on;
#超时时间
keepalive_timeout 65;
#gzip on;
#通过nginx上传文件的大小
client_max_body_size 1000M;
#动态服务器组(webbas网关)
upstream webbas_gateway {
server 10.1.5.174:9088;
server 10.1.5.176:9088;
ip_hash;#依据ip分配方式,保证每个访客固定访问一个后端服务器
#keepalive 1024;
}
#动态服务器组(server)
upstream atmp_client {
server 10.1.5.174:8099;
server 10.1.5.176:8099;
ip_hash;
#keepalive 1024;
}
#动态服务器组(文件服务器)
upstream atap_fastdfs {
server 10.1.5.181:8011;
#keepalive 1024;
}
#开启websocket代理功能
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
#配置虚拟机
server {
#虚拟机监听端口
listen 8090;
#虚拟机访问域名
server_name localhost;
#隐藏版本号
server_tokens off;
#设置编码格式
charset utf-8;
#指定日志存放路径
access_log /nginx/logs/user.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# webbas前端访问后台(对含有web的地址进行负载均衡)
location ~/web {
#设置被代理服务器的端口及url
proxy_pass http://webbas_gateway;
add_header From localhost;
#proxy_cookie_path /admin/ /;
#proxy_cookie_path /admin /;
#将代理服务器的用户信息传到真实服务器
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
}
#文件服务器
location /res {
proxy_pass http://atap_fastdfs/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
add_header Content-Disposition "attachment;filename=$arg_attname";
}
#前端CAS登录
location = /casIndex {
if ( $uri != '/web/cas/login' ) {
rewrite '/casIndex' '/web/cas/login' last;
}
}
#前端CAS登出
location = /casLogout {
if ( $uri != '/web/cas/logout' ) {
rewrite '/casLogout' '/web/cas/logout' last;
}
}
}
server {
listen 8080;
server_name localhost;
server_tokens off;
charset utf-8;
access_log /nginx/logs/mobile.access.log main;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# webbas前端访问后台
location ~/atmp/web/api {
proxy_pass http://atmp_client;
add_header From localhost;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
}
location /res {
proxy_pass http://atap_fastdfs/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
}
}
#client_body_temp_path /tmp/client_temp;
#proxy_temp_path /tmp/proxy_temp_path;
#fastcgi_temp_path /tmp/fastcgi_temp;
#uwsgi_temp_path /tmp/uwsgi_temp;
#scgi_temp_path /tmp/scgi_temp;
}
网友评论