您好,登录后才能下订单哦!
本篇内容介绍了“Nginx反向代理和负载均衡部署方法”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
															nginx反向代理与负载均衡
upstream proxy.test.com {
			             #ip_hash;
			             server 192.168.6.119:9090;
			             server 192.168.6.119:8090;
			         }
			server {
			        listen 80;
			        server_name proxy.test.com;
			        location / {
			          proxy_set_header Host $host;
			          proxy_set_header X-Real-IP $remote_addr;
			          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			 
			             #禁用缓存
			             proxy_buffering off;
			 
			             #反向代理的地址
			             proxy_pass http://proxy.test.com; 
			        }
}
[root@node3 vhost]# curl proxy.test.com
119
[root@node3 vhost]# curl proxy.test.com
nginx2
[root@node3 vhost]# curl proxy.test.com
119
[root@node3 vhost]# curl proxy.test.com
nginx2
upstream oc_haodai_com {
			        server 192.168.1.37:8080 weight=2 max_fails=2 fail_timeout=30s;
			      # server 192.168.1.38:8080 weight=2 max_fails=2 fail_timeout=30s;
			      #server 192.168.1.39:8080 weight=2 max_fails=2 fail_timeout=30s;
			}
			server {
			        listen 443;    ###https的默认端口  http是80
			    
			        server_name oc.haodai.com;
			        ssl on;
			         ssl_certificate /usr/local/nginx1.8/conf/haodai.com.crt;
			         ssl_certificate_key /usr/local/nginx1.8/conf/haodai.com.key;
			        location / {
			                proxy_next_upstream http_502 http_504 http_404 error timeout invalid_header;
			                proxy_set_header Host $host;
			                proxy_set_header X-Real-IP $remote_addr;
			                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			                #session_sticky_hide_cookie upstream=account.free4lab.com;
			                proxy_pass http://oc_haodai_com;
			        }
			    access_log /home/wwwlogs/oc.haodai.com.proxy.log access;
			}
			server {
			        listen 80;
			        server_name oc.haodai.com;
			        location / {
			                proxy_next_upstream http_502 http_504 http_404 error timeout invalid_header;
			                proxy_set_header Host $host;
			                proxy_set_header X-Real-IP $remote_addr;
			                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			                #session_sticky_hide_cookie upstream=account.free4lab.com;
			                proxy_pass http://oc_haodai_com;
			        }
}
37.38.39上配置文件
[root@order_web04 vhost]# more oc.haodai.com.conf 
			server {
			        listen       8080;
			        server_name  oc.haodai.com;
			        index index.html index.htm index.php;
			        root  /home/wwwroot/order_center;
			        access_log /home/wwwlogs/oc.haodai.com.log access;
			        location / {
			            index index.php;
			            if ( !-e $request_filename){
			                rewrite ^/(.*)$ /index.php?s=$1 last;
			                break;
			            }
			        }
			        location ^~ /.git {
			            return 403;
			        }
			        location ~ /Common/sh/.*\.(php|php5|sh|py|pl)$ {
			            deny all;
			        }
			        if ($request_uri ~* "/Common/") {
			                return 403;
			        }
			        if ($request_uri ~* "/Common/sh") {
			                return 403;
			        }
			        location ~ .*\.(php|php5)?$ {
			            try_files $uri =404;
			            fastcgi_pass  127.0.0.1:9000;
			            fastcgi_index index.php;
			            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
			            include fastcgi_params;
			        }
			        if ( $fastcgi_script_name ~ \..*\/.*php ) {
			            return 403;
			        }
}
“Nginx反向代理和负载均衡部署方法”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。