飞道的博客

Nginx 配置反向代理

562人阅读  评论(0)

 

1.创建配置文件 ext.conf


  
  1. server {
  2. listen 8011; # 访问端口
  3. server_name localhost;
  4. #charset koi8-r;
  5. #access_log /var/log/nginx/host.access.log main;
  6. location / {
  7. proxy_pass http: //192.168.100.135:8011/; # 代理接口地址
  8. proxy_set_header Host $host;
  9. proxy_set_header X-Real-IP $remote_addr;
  10. proxy_set_header x_real_ipP $remote_addr;
  11. proxy_set_header remote_addr $remote_addr;
  12. proxy_set_header X-Forwarded- For $proxy_add_x_forwarded_for;
  13. proxy_http_version 1.1;
  14. proxy_connect_timeout 300s;
  15. proxy_read_timeout 300s;
  16. proxy_send_timeout 300s;
  17. proxy_set_header Upgrade $http_upgrade;
  18. proxy_set_header Connection upgrade;
  19. }
  20. #error_page 404 /404.html;
  21. # redirect server error pages to the static page /50x.html
  22. #
  23. error_page 500 502 503 504 / 50x.html;
  24. location = / 50x.html {
  25. root /usr/share/nginx/html;
  26. }
  27. }
  28. server {
  29. listen 8088; # 访问端口
  30. server_name localhost;
  31. #charset koi8-r;
  32. #access_log /var/log/nginx/host.access.log main;
  33. location /cluster {
  34. proxy_pass http: //192.168.100.103:8088/cluster/; # 代理接口地址
  35. proxy_set_header Host $host;
  36. proxy_set_header X-Real-IP $remote_addr;
  37. proxy_set_header x_real_ipP $remote_addr;
  38. proxy_set_header remote_addr $remote_addr;
  39. proxy_set_header X-Forwarded- For $proxy_add_x_forwarded_for;
  40. proxy_http_version 1.1;
  41. proxy_connect_timeout 300s;
  42. proxy_read_timeout 300s;
  43. proxy_send_timeout 300s;
  44. proxy_set_header Upgrade $http_upgrade;
  45. proxy_set_header Connection upgrade;
  46. }
  47. location /logs {
  48. proxy_pass http: //192.168.100.103:8088/logs/; # 接口地址
  49. proxy_set_header Host $host;
  50. proxy_set_header X-Real-IP $remote_addr;
  51. proxy_set_header x_real_ipP $remote_addr;
  52. proxy_set_header remote_addr $remote_addr;
  53. proxy_set_header X-Forwarded- For $proxy_add_x_forwarded_for;
  54. proxy_http_version 1.1;
  55. proxy_connect_timeout 300s;
  56. proxy_read_timeout 300s;
  57. proxy_send_timeout 300s;
  58. proxy_set_header Upgrade $http_upgrade;
  59. proxy_set_header Connection upgrade;
  60. }
  61. #error_page 404 /404.html;
  62. # redirect server error pages to the static page /50x.html
  63. #
  64. error_page 500 502 503 504 / 50x.html;
  65. location = / 50x.html {
  66. root /usr/share/nginx/html;
  67. }
  68. }

2.将配置文件存放到指定配置文件目录

/etc/nginx/conf.d

本文采用的 nginx 是用 yum 安装的,所以配置文件路径目录是/etc/nginx/conf.d.

 

3.重新加载配置文件

3.1.运行
nginx


3.2. 重新加载配置文件
nginx -s reload

3.3. 验证配置文件
nginx -t

3.4.停止

nginx -s stop
 

 

 

 


转载:https://blog.csdn.net/zhanglong_4444/article/details/104275553
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场