| | |
| | | user nginx; |
| | | # Windows Nginx 主配置文件 |
| | | |
| | | worker_processes auto; |
| | | |
| | | error_log /var/log/nginx/error.log notice; |
| | | pid /var/run/nginx.pid; |
| | | error_log logs/error.log notice; |
| | | pid logs/nginx.pid; |
| | | |
| | | events { |
| | | worker_connections 2048; |
| | | } |
| | | |
| | | http { |
| | | include /etc/nginx/mime.types; |
| | | include 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; |
| | | error_log /var/log/nginx/error.log error; |
| | | log_format api_log '$remote_addr - $remote_user [$time_local] ' |
| | | '"$request_method $request_uri HTTP/$server_protocol" ' |
| | | '$status $body_bytes_sent "$http_referer" ' |
| | | '"$http_user_agent" "$http_x_forwarded_for" ' |
| | | 'request_time="$request_time" ' |
| | | 'upstream_response_time="$upstream_response_time" ' |
| | | 'request_length="$request_length"'; |
| | | |
| | | log_format json_log '$remote_addr - $remote_user [$time_local] ' |
| | | '"$request_method $request_uri HTTP/$server_protocol" ' |
| | | '$status $body_bytes_sent ' |
| | | '"$http_referer" "$http_user_agent" ' |
| | | '"$http_x_forwarded_for" ' |
| | | 'request_body="$request_body" ' |
| | | 'content_type="$content_type" ' |
| | | 'request_time="$request_time" ' |
| | | 'upstream_response_time="$upstream_response_time"'; |
| | | |
| | | # 全局日志(server 中可覆盖) |
| | | access_log logs/access.log main; |
| | | error_log logs/error.log error; |
| | | |
| | | # 全局配置 |
| | | client_max_body_size 300M; |
| | | |
| | | upstream api_backend { |
| | | server 10.10.10.199:8088; |
| | | # ...... |
| | | } |
| | | |
| | | server { |
| | | listen 80; |
| | | listen 8080; |
| | | server_name localhost; |
| | | |
| | | location / { |
| | | root /app/www; |
| | | try_files $uri $uri/ /index.html; |
| | | index index.html index.htm; |
| | | } |
| | | |
| | | # Http |
| | | location /api/ { |
| | | # rewrite ^/api/(.*)$ /$1 break; # if you wanna remove proxy prefix |
| | | proxy_pass http://api_backend/api/; |
| | | proxy_set_header Host $host; |
| | | proxy_set_header X-Real-IP $remote_addr; |
| | | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| | | proxy_set_header X-Forwarded-Proto $scheme; |
| | | |
| | | # buffer |
| | | proxy_buffers 8 16k; |
| | | proxy_buffer_size 32k; |
| | | |
| | | # timeout |
| | | # proxy_connect_timeout 60s; |
| | | # proxy_read_timeout 60s; |
| | | # proxy_send_timeout 60s; |
| | | } |
| | | |
| | | # WebSocket |
| | | location /ws/ { |
| | | # ws |
| | | proxy_pass http://api_backend/ws/; |
| | | # wss |
| | | # proxy_pass wss://api_backend/ws/; |
| | | |
| | | proxy_http_version 1.1; |
| | | proxy_set_header Upgrade $http_upgrade; |
| | | proxy_set_header Connection "upgrade"; |
| | | proxy_set_header Host $host; |
| | | proxy_set_header X-Real-IP $remote_addr; |
| | | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| | | proxy_set_header X-Forwarded-Proto $scheme; |
| | | proxy_buffering off; |
| | | |
| | | # timeout |
| | | # proxy_connect_timeout 60s; |
| | | # proxy_read_timeout 60s; |
| | | # proxy_send_timeout 60s; |
| | | } |
| | | |
| | | # HTTPS |
| | | # listen 443 ssl; |
| | | # ssl_certificate /path/to/cert.pem; |
| | | # ssl_certificate_key /path/to/key.pem; |
| | | |
| | | error_page 500 502 503 504 /50x.html; |
| | | |
| | | location = /50x.html { |
| | | root html; |
| | | } |
| | | |
| | | } |
| | | |
| | | sendfile on; |
| | | #tcp_nopush on; |
| | | |
| | | tcp_nopush on; |
| | | tcp_nodelay on; |
| | | keepalive_timeout 65; |
| | | |
| | | #gzip on; |
| | | # Gzip 压缩 |
| | | gzip on; |
| | | gzip_vary on; |
| | | gzip_min_length 1000; |
| | | gzip_proxied any; |
| | | gzip_comp_level 6; |
| | | gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/rss+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml; |
| | | |
| | | include /etc/nginx/conf.d/*.conf; |
| | | # 后端服务器配置 |
| | | upstream api_backend { |
| | | server 127.0.0.1:8081; |
| | | } |
| | | |
| | | upstream server_backend { |
| | | server 127.0.0.1:8085; |
| | | } |
| | | |
| | | # 引入 server 配置 |
| | | include conf.d/*.conf; |
| | | } |