nginx 跳转

 nginx 跳转

一.需求:当需要在别的机访问本机房的服务器问题。

虚拟主机头配置

 1     server {
 2         listen       80;
 3         server_name test.zlx.com;
 4         location / {
 5         if ($request_method = 'DELETE' ) {
 6                         return 405;
 7                         }
 8                proxy_pass http://test;
 9                  }
10 
11         location = /404.html {
12              root    /home/usr/local/nginx/html;
13                           }
14         location = /403.html {
15              root    /home/usr/local/nginx/html;
16                           }
17         location = /500.html {
18              root    /home/usr/local/nginx/html;
19                           }
20         location = /502.html {
21              root    /home/usr/local/nginx/html;
22                           }
23         location = /503.html {
24              root    /home/usr/local/nginx/html;
25                           }
26         location = /504.html {
27              root    /home/usr/local/nginx/html;
28                           }
29                 }
30 
31 
32     server {
33         server_name test.zlx.com;
34         listen 443;
35 
36     ssl on;
37     ssl_certificate    /home/usr/local/nginx/cert/323432432.pem;
38     ssl_certificate_key   /home/usr/local/nginx/cert/324324324.key;
39     ssl_session_timeout 5m;
40     ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
41     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
42     ssl_prefer_server_ciphers on;
43 
44 
45 #################################################################
46         location / {
47         if ($request_method = 'DELETE' ) {
48                         return 405;
49                         }
50 
51                proxy_pass http://test;
52        }
53 #################################################################
54 
55         location = /404.html {
56              root    /home/usr/local/nginx/html;
57                           }
58         location = /403.html {
59              root    /home/usr/local/nginx/html;
60                           }
61         location = /500.html {
62              root    /home/usr/local/nginx/html;
63                           }
64         location = /502.html {
65              root    /home/usr/local/nginx/html;
66                           }
67         location = /503.html {
68              root    /home/usr/local/nginx/html;
69                           }
70         location = /504.html {
71              root    /home/usr/local/nginx/html;
72                           }
73     }
View Code

最后在host文件修改

别的机房的Ip   test.zlx.com

最后进行访问。

原文地址:https://www.cnblogs.com/zoulixiang/p/9412264.html