user root; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; client_max_body_size 20m; map $time_iso8601 $logdate { '~^(?\d{4}-\d{2}-\d{2})' $ymd; default 'date-not-found'; } log_format main '$remote_addr [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer"'; root /var/log/nginx; access_log /var/log/nginx/access-$logdate.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; server { listen 3001; server_name 144.123.43.138; absolute_redirect off; #取消绝对路径的重定向 sendfile on; default_type application/octet-stream; gzip on; gzip_http_version 1.1; gzip_disable "MSIE [1-6]\."; gzip_min_length 256; gzip_vary on; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript; gzip_comp_level 9; root /usr/share/nginx/html; location / { # same docker config root /usr/share/nginx/html; index index.html; # support history mode try_files $uri $uri/ /index.html; } # 后端服务 location ^~ /api/ { proxy_pass http://huaxin-admin-server:8001/api/; # 转发规则 proxy_set_header Host $proxy_host; # 修改转发请求头,让目标应用可以受到真实的请求 proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } # websocket服务 location ^~ /ws-api/ { proxy_pass http://huaxin-admin-server:8002/ws-api/; proxy_read_timeout 300s; proxy_send_timeout 300s; 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_http_version 1.1; } # 文件访问 location ^~ /upload/ { proxy_pass http://huaxin-admin-server:8001/upload/; proxy_set_header Host $proxy_host; # 修改转发请求头,让目标应用可以受到真实的请求 proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }