nginx代理配置


nginx代理配置

1、linux安裝nginx默認目錄

自動安裝的nginx再linux下默認路徑在 

/etc/nginx

啟動路徑在/usr/sbin/

2、默認配置文件是

/etc/nginx/nginx.conf

 1 # For more information on configuration, see:
 2 #   * Official English Documentation: http://nginx.org/en/docs/
 3 #   * Official Russian Documentation: http://nginx.org/ru/docs/
 4 
 5 user nginx;
 6 worker_processes auto;
 7 error_log /var/log/nginx/error.log;
 8 pid /run/nginx.pid;
 9 
10 # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
11 # 可以加載指定路徑下的配置文件加載到系統
12 include /usr/share/nginx/modules/*.conf;
13 
14 events {
15     worker_connections 1024;
16 }
17 
18 http {
19     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
20                       '$status $body_bytes_sent "$http_referer" '
21                       '"$http_user_agent" "$http_x_forwarded_for"';
22 
23     access_log  /var/log/nginx/access.log  main;
24 
25     sendfile            on;
26     tcp_nopush          on;
27     tcp_nodelay         on;
28     keepalive_timeout   65;
29     types_hash_max_size 4096;
30 
31     include             /etc/nginx/mime.types;
32     default_type        application/octet-stream;
33 
34     # Load modular configuration files from the /etc/nginx/conf.d directory.
35     # See http://nginx.org/en/docs/ngx_core_module.html#include
36     # for more information.
37     include /etc/nginx/conf.d/*.conf;
38 
39     server {
40         listen       80;
41         listen       [::]:80;
42         server_name  _;
43         root         /usr/share/nginx/html;
44 
45         # Load configuration files for the default server block.
46         include /etc/nginx/default.d/*.conf;
47 
48         error_page 404 /404.html;
49         location = /404.html {
50         }
51 
52         error_page 500 502 503 504 /50x.html;
53         location = /50x.html {
54         }
55     }
56 
57 # Settings for a TLS enabled server.
58 #
59 #    server {
60 #        listen       443 ssl http2;
61 #        listen       [::]:443 ssl http2;
62 #        server_name  _;
63 #        root         /usr/share/nginx/html;
64 #
65 #        ssl_certificate "/etc/pki/nginx/server.crt";
66 #        ssl_certificate_key "/etc/pki/nginx/private/server.key";
67 #        ssl_session_cache shared:SSL:1m;
68 #        ssl_session_timeout  10m;
69 #        ssl_ciphers HIGH:!aNULL:!MD5;
70 #        ssl_prefer_server_ciphers on;
71 #
72 #        # Load configuration files for the default server block.
73 #        include /etc/nginx/default.d/*.conf;
74 #
75 #        error_page 404 /404.html;
76 #            location = /40x.html {
77 #        }
78 #
79 #        error_page 500 502 503 504 /50x.html;
80 #            location = /50x.html {
81 #        }
82 #    }
83 
84 }

3、include /etc/nginx/conf.d/*.conf;

可以對配置文件進行分類的工作,內容如下

 1         server {
 2             listen       8088;# 訪問端口
 3             server_name  localhost;
 4             #charset koi8-r;
 5             #access_log  /var/log/nginx/host.access.log  main;
 6 
 7             location /dss/visualis {
 8             root   /data/project/web; # 靜態文件目錄
 9             autoindex on;
10             }
11 
12             location /dss/linkis {
13              root   /data/project/web; # 管理台的靜態文件目錄
14              autoindex on;
15             }
16 
17             location / {
18             root   /data/project/web/dist; # 靜態文件目錄
19             index  index.html index.html;
20             }
21 
22              location /datacenter {
23              root   /data/project/dataCenter; # 管理台的靜態文件目錄
24              index  index.html index.html;
25        }
26 
27 
28 
29 
30             location /ws {
31             proxy_pass http://localhost:9001;#后端的地址
32             proxy_http_version 1.1;
33             proxy_set_header Upgrade $http_upgrade;
34             proxy_set_header Connection upgrade;
35             }
36 
37 
38             location /warehouseHttp {
39             proxy_pass http://localhost:9088/dss/shucang; #后端地址
40             proxy_set_header Host $host;
41             proxy_set_header X-Real-IP $remote_addr;
42             proxy_set_header x_real_ipP $remote_addr;
43             proxy_set_header remote_addr $remote_addr;
44             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
45             proxy_http_version 1.1;
46             proxy_connect_timeout 4s;
47             proxy_read_timeout 600s;
48             proxy_send_timeout 12s;
49             proxy_set_header Upgrade $http_upgrade;
50             proxy_set_header Connection upgrade;
51             }            
52 
53             location /api {
54             proxy_pass http://localhost:9001; #后端的地址
55             proxy_set_header Host $host;
56             proxy_set_header X-Real-IP $remote_addr;
57             proxy_set_header x_real_ipP $remote_addr;
58             proxy_set_header remote_addr $remote_addr;
59             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
60             proxy_http_version 1.1;
61             proxy_connect_timeout 4s;
62             proxy_read_timeout 600s;
63             proxy_send_timeout 12s;
64             proxy_set_header Upgrade $http_upgrade;
65             proxy_set_header Connection upgrade;
66             }
67 
68             #error_page  404              /404.html;
69             # redirect server error pages to the static page /50x.html
70             #
71             error_page   500 502 503 504  /50x.html;
72             location = /50x.html {
73             root   /usr/share/nginx/html;
74             }
75         }
76     

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM