nginx.conf 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. user nginx;
  2. worker_processes 1;
  3. error_log /var/log/nginx/error.log warn;
  4. pid /var/run/nginx.pid;
  5. events {
  6. worker_connections 1024;
  7. }
  8. http {
  9. include /etc/nginx/mime.types;
  10. default_type application/octet-stream;
  11. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  12. '$status $body_bytes_sent "$http_referer" '
  13. '"$http_user_agent" "$http_x_forwarded_for"';
  14. access_log /var/log/nginx/access.log main;
  15. sendfile on;
  16. keepalive_timeout 65;
  17. upstream cool {
  18. server midway:8001;
  19. }
  20. server {
  21. listen 80;
  22. server_name localhost;
  23. location / {
  24. root /app;
  25. index index.html;
  26. try_files $uri $uri/ /index.html;
  27. }
  28. location /api/
  29. {
  30. proxy_pass http://cool/;
  31. proxy_set_header Host $host;
  32. proxy_set_header X-Real-IP $remote_addr;
  33. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  34. proxy_set_header REMOTE-HOST $remote_addr;
  35. #缓存相关配置
  36. #proxy_cache cache_one;
  37. #proxy_cache_key $host$request_uri$is_args$args;
  38. #proxy_cache_valid 200 304 301 302 1h;
  39. #持久化连接相关配置
  40. proxy_connect_timeout 3000s;
  41. proxy_read_timeout 86400s;
  42. proxy_send_timeout 3000s;
  43. #proxy_http_version 1.1;
  44. #proxy_set_header Upgrade $http_upgrade;
  45. #proxy_set_header Connection "upgrade";
  46. add_header X-Cache $upstream_cache_status;
  47. #expires 12h;
  48. }
  49. # socket需额外配置
  50. location /socket {
  51. proxy_pass http://cool/socket;
  52. proxy_connect_timeout 3600s; #配置点1
  53. proxy_read_timeout 3600s; #配置点2,如果没效,可以考虑这个时间配置长一点
  54. proxy_send_timeout 3600s; #配置点3
  55. proxy_set_header Host $host;
  56. proxy_set_header X-Real-IP $remote_addr;
  57. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  58. proxy_set_header REMOTE-HOST $remote_addr;
  59. #proxy_bind $remote_addr transparent;
  60. proxy_http_version 1.1;
  61. proxy_set_header Upgrade $http_upgrade;
  62. proxy_set_header Connection "upgrade";
  63. rewrite /socket/(.*) /$1 break;
  64. proxy_redirect off;
  65. }
  66. }
  67. }