[关闭]
@liruiyi962464 2024-09-18T23:33:16.000000Z 字数 8548 阅读 62

Nginx配置文件

代码

方案一

  1. user root;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. sendfile on;
  14. #tcp_nopush on;
  15. #keepalive_timeout 0;
  16. keepalive_timeout 65;
  17. server_tokens off;
  18. #gzip on;
  19. upstream jeecg-boot_server{
  20. server 202.207.122.52:8080;
  21. }
  22. server {
  23. listen 13000;
  24. server_name localhost;
  25. client_max_body_size 20m;
  26. #添加头部信息
  27. proxy_set_header Cookie $http_cookie;
  28. proxy_set_header X-Forwarded-Host $host;
  29. proxy_set_header X-Forwarded-Server $host;
  30. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  31. proxy_set_header X-real-ip $remote_addr;
  32. location ~* /.+jmreport.+ {
  33. # 使用if指令和=403来拒绝访问
  34. if ($request_uri ~* "jmreport") {
  35. return 403;
  36. }
  37. }
  38. location /yunwei/ {
  39. rewrite ^/(.*)/yunwei/yunwei(.*)$ /$1/yunwei$2 last;
  40. proxy_set_header Host $Host;
  41. proxy_set_header X-Forward-For $remote_addr;
  42. proxy_pass http://jeecg-boot_server;
  43. }
  44. location / {
  45. rewrite ^/(.*)/yunwei/yunwei(.*)$ /$1/yunwei$2 last;
  46. root /home/web/deploy/yunwei;
  47. index index.html index.htm;
  48. }
  49. error_page 404 /index.html;
  50. error_page 500 502 503 504 /50x.html;
  51. location = /50x.html {
  52. root html;
  53. }
  54. }
  55. }

方案二

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. # ...
  12. # 设置连接超时时间为30秒
  13. fastcgi_connect_timeout 600s;
  14. # 设置请求超时时间为60秒
  15. fastcgi_send_timeout 600s;
  16. fastcgi_read_timeout 600s;
  17. proxy_send_timeout 600s;
  18. proxy_read_timeout 600s;
  19. client_body_timeout 600s;
  20. client_header_timeout 600s;
  21. include mime.types;
  22. default_type application/octet-stream;
  23. sendfile on;
  24. #tcp_nopush on;
  25. #keepalive_timeout 0;
  26. keepalive_timeout 65;
  27. server {
  28. listen 3031;
  29. server_name localhost;
  30. #添加头部信息
  31. proxy_set_header Cookie $http_cookie;
  32. proxy_set_header X-Forwarded-Host $host;
  33. proxy_set_header X-Forwarded-Server $host;
  34. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  35. proxy_set_header X-real-ip $remote_addr;
  36. client_max_body_size 500m;
  37. #添加拦截路径和代理地址
  38. location /api/ {
  39. proxy_pass http://192.168.10.26:8899/; #注意:使用代理地址时末尾记得加上斜杠"/"。
  40. }
  41. location /jeecg-boot-file {
  42. #proxy_set_header Host $Host;
  43. #proxy_set_header X-Forward-For $remote_addr;
  44. proxy_pass http://127.0.0.1:8899;
  45. }
  46. location /jeecg-boot {
  47. proxy_set_header Host $Host;
  48. proxy_set_header X-Forward-For $remote_addr;
  49. proxy_pass http://127.0.0.1:8899;
  50. }
  51. location / {
  52. root E:\\shuohuang_nginx\\shuohuang_nginx-1.20.2\\html\\dist;
  53. index index.html index.htm;
  54. }
  55. error_page 404 /index.html;
  56. error_page 500 502 503 504 /50x.html;
  57. location = /50x.html {
  58. root html;
  59. }
  60. }
  61. }

多重部署

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. # ...
  12. # 设置连接超时时间为30秒
  13. fastcgi_connect_timeout 600s;
  14. # 设置请求超时时间为60秒
  15. fastcgi_send_timeout 600s;
  16. fastcgi_read_timeout 600s;
  17. proxy_send_timeout 600s;
  18. proxy_read_timeout 600s;
  19. client_body_timeout 600s;
  20. client_header_timeout 600s;
  21. include mime.types;
  22. default_type application/octet-stream;
  23. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  24. # '$status $body_bytes_sent "$http_referer" '
  25. # '"$http_user_agent" "$http_x_forwarded_for"';
  26. #access_log logs/access.log main;
  27. sendfile on;
  28. #tcp_nopush on;
  29. #keepalive_timeout 0;
  30. keepalive_timeout 65;
  31. #gzip on;
  32. server {
  33. listen 3030;
  34. server_name localhost;
  35. #添加头部信息
  36. proxy_set_header Cookie $http_cookie;
  37. proxy_set_header X-Forwarded-Host $host;
  38. proxy_set_header X-Forwarded-Server $host;
  39. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  40. proxy_set_header X-real-ip $remote_addr;
  41. #charset koi8-r;
  42. #access_log logs/host.access.log main;
  43. client_max_body_size 500m;
  44. #添加拦截路径和代理地址
  45. location /api/ {
  46. proxy_pass http://127.0.0.1:8090/; #注意:使用代理地址时末尾记得加上斜杠"/"。
  47. }
  48. location /jeecg-boot-file {
  49. #proxy_set_header Host $Host;
  50. #proxy_set_header X-Forward-For $remote_addr;
  51. proxy_pass http://127.0.0.1:8090;
  52. }
  53. location /jeecg-boot {
  54. proxy_set_header Host $Host;
  55. proxy_set_header X-Forward-For $remote_addr;
  56. proxy_pass http://127.0.0.1:8090;
  57. }
  58. location / {
  59. root ./html/dist_sp;
  60. index index.html index.htm;
  61. try_files $uri $uri/ /index.html =404;
  62. }
  63. #error_page 404 /404.html;
  64. # redirect server error pages to the static page /50x.html
  65. #
  66. error_page 500 502 503 504 /50x.html;
  67. location = /50x.html {
  68. root html;
  69. }
  70. }
  71. server{
  72. listen 3031;
  73. server_name localhost;
  74. #添加头部信息
  75. proxy_set_header Cookie $http_cookie;
  76. proxy_set_header X-Forwarded-Host $host;
  77. proxy_set_header X-Forwarded-Server $host;
  78. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  79. proxy_set_header X-real-ip $remote_addr;
  80. #charset koi8-r;
  81. #access_log logs/host.access.log main;
  82. client_max_body_size 500m;
  83. #添加拦截路径和代理地址
  84. location /api/ {
  85. proxy_pass http://127.0.0.1:8091/; #注意:使用代理地址时末尾记得加上斜杠"/"。
  86. }
  87. location /jeecg-boot-file {
  88. #proxy_set_header Host $Host;
  89. #proxy_set_header X-Forward-For $remote_addr;
  90. proxy_pass http://127.0.0.1:8091;
  91. }
  92. location /jeecg-boot {
  93. proxy_set_header Host $Host;
  94. proxy_set_header X-Forward-For $remote_addr;
  95. proxy_pass http://127.0.0.1:8091;
  96. }
  97. location / {
  98. root ./html/dist_lte;
  99. index index.html index.htm;
  100. try_files $uri $uri/ /index.html =404;
  101. }
  102. #error_page 404 /404.html;
  103. # redirect server error pages to the static page /50x.html
  104. #
  105. error_page 500 502 503 504 /50x.html;
  106. location = /50x.html {
  107. root html;
  108. }
  109. }
  110. # another virtual host using mix of IP-, name-, and port-based configuration
  111. #
  112. #server {
  113. # listen 8000;
  114. # listen somename:8080;
  115. # server_name somename alias another.alias;
  116. # location / {
  117. # root html;
  118. # index index.html index.htm;
  119. # }
  120. #}
  121. # HTTPS server
  122. #
  123. #server {
  124. # listen 443 ssl;
  125. # server_name localhost;
  126. # ssl_certificate cert.pem;
  127. # ssl_certificate_key cert.key;
  128. # ssl_session_cache shared:SSL:1m;
  129. # ssl_session_timeout 5m;
  130. # ssl_ciphers HIGH:!aNULL:!MD5;
  131. # ssl_prefer_server_ciphers on;
  132. # location / {
  133. # root html;
  134. # index index.html index.htm;
  135. # }
  136. #}
  137. }

涉及使用websocket 这样子配置

  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. # ...
  12. # 设置连接超时时间为30秒
  13. fastcgi_connect_timeout 600s;
  14. # 设置请求超时时间为60秒
  15. fastcgi_send_timeout 600s;
  16. fastcgi_read_timeout 600s;
  17. proxy_send_timeout 600s;
  18. proxy_read_timeout 600s;
  19. client_body_timeout 600s;
  20. client_header_timeout 600s;
  21. include mime.types;
  22. default_type application/octet-stream;
  23. sendfile on;
  24. #tcp_nopush on;
  25. #keepalive_timeout 0;
  26. keepalive_timeout 65;
  27. #定义变量,兼容HTTP和websocket两种请求协议
  28. map $http_upgrade $connection_upgrade {
  29. default keep-alive; #默认 keep-alive,表示HTTP协议。
  30. 'websocket' upgrade;#若是 websocket 请求,则升级协议 upgrade
  31. }
  32. #物流港大屏1
  33. server {
  34. listen 3000;
  35. server_name localhost;
  36. #添加头部信息
  37. proxy_set_header Cookie $http_cookie;
  38. proxy_set_header X-Forwarded-Host $host;
  39. proxy_set_header X-Forwarded-Server $host;
  40. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  41. proxy_set_header X-real-ip $remote_addr;
  42. client_max_body_size 500m;
  43. #添加拦截路径和代理地址
  44. location /api/ {
  45. proxy_pass http://localhost:8080/; #注意:使用代理地址时末尾记得加上斜杠"/"。
  46. }
  47. location /jeecg-boot-file {
  48. #proxy_set_header Host $Host;
  49. #proxy_set_header X-Forward-For $remote_addr;
  50. proxy_pass http://localhost:8080;
  51. }
  52. location /jeecg-boot {
  53. proxy_set_header Host $Host;
  54. proxy_set_header X-Forward-For $remote_addr;
  55. proxy_pass http://localhost:8080;
  56. }
  57. #websocket的代理规则
  58. location /jeecg-boot/websocket {
  59. proxy_pass http://localhost:8080; #转发到后端接口
  60. proxy_read_timeout 60s; #设置超时时间,默认是60
  61. proxy_http_version 1.1;
  62. proxy_set_header Host $host;#这个配置不要漏了,必须要
  63. proxy_set_header Upgrade $http_upgrade;
  64. proxy_set_header Connection $connection_upgrade;
  65. }
  66. location / {
  67. root C:\\wuliugang1\\nginx-1.20.2\\html\\dist1;
  68. index index.html index.htm;
  69. }
  70. error_page 404 /index.html;
  71. error_page 500 502 503 504 /50x.html;
  72. location = /50x.html {
  73. root html;
  74. }
  75. }
  76. # 物流港大屏2
  77. server {
  78. listen 3001;
  79. server_name localhost;
  80. #添加头部信息
  81. proxy_set_header Cookie $http_cookie;
  82. proxy_set_header X-Forwarded-Host $host;
  83. proxy_set_header X-Forwarded-Server $host;
  84. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  85. proxy_set_header X-real-ip $remote_addr;
  86. client_max_body_size 500m;
  87. #添加拦截路径和代理地址
  88. location /api/ {
  89. proxy_pass http://localhost:8099/; #注意:使用代理地址时末尾记得加上斜杠"/"。
  90. }
  91. location /jeecg-boot-file {
  92. #proxy_set_header Host $Host;
  93. #proxy_set_header X-Forward-For $remote_addr;
  94. proxy_pass http://localhost:8099;
  95. }
  96. location /jeecg-boot {
  97. proxy_set_header Host $Host;
  98. proxy_set_header X-Forward-For $remote_addr;
  99. proxy_pass http://localhost:8099;
  100. }
  101. location / {
  102. root C:\\wuliugang1\\nginx-1.20.2\\html\\dist2;
  103. index index.html index.htm;
  104. }
  105. #websocket的代理规则
  106. location /jeecg-boot/websocket {
  107. proxy_pass http://localhost:8099; #转发到后端接口
  108. proxy_read_timeout 60s; #设置超时时间,默认是60
  109. proxy_http_version 1.1;
  110. proxy_set_header Host $host;#这个配置不要漏了,必须要
  111. proxy_set_header Upgrade $http_upgrade;
  112. proxy_set_header Connection $connection_upgrade;
  113. }
  114. error_page 404 /index.html;
  115. error_page 500 502 503 504 /50x.html;
  116. location = /50x.html {
  117. root html;
  118. }
  119. }
  120. #定时任务项目
  121. server {
  122. listen 3033;
  123. server_name localhost;
  124. charset utf-8;
  125. location / {
  126. root C:\\task\\task_ui;
  127. try_files $uri $uri/ /index.html;
  128. index index.html index.htm;
  129. }
  130. location /prod-api/ {
  131. proxy_set_header Host $http_host;
  132. proxy_set_header X-Real-IP $remote_addr;
  133. proxy_set_header REMOTE-HOST $remote_addr;
  134. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  135. proxy_pass http://localhost:9080/;
  136. }
  137. error_page 500 502 503 504 /50x.html;
  138. location = /50x.html {
  139. root html;
  140. }
  141. }
  142. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注