【Nginx】Nginx反向代理和負載均衡部署
nginx反向代理與負載均衡
[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
37.38.39上配置檔案
-
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;
-
}
-
- }
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;
-
}
- }
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2133980/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Nginx反向代理負載均衡的容器化部署Nginx負載
- nginx詳解反向代理負載均衡Nginx負載
- Nginx入門(2)反向代理和負載均衡Nginx負載
- docker下nginx反向代理和負載均衡配置DockerNginx負載
- nginx面試題-nginx負載均衡與正反向代理Nginx面試題負載
- Nginx負載均衡反向代理伺服器Nginx負載伺服器
- [原創]Nginx反向代理及負載均衡Nginx負載
- nginx反向代理和負載均衡策略實戰案例Nginx負載
- 介紹下Nginx 反向代理與負載均衡Nginx負載
- nginx+tomcat反向代理負載均衡配置NginxTomcat負載
- nginx配置web服務|反向代理|負載均衡NginxWeb負載
- nginx+tomcat實現反向代理+負載均衡NginxTomcat負載
- Nginx搭建反向代理負載均衡和web快取伺服器Nginx負載Web快取伺服器
- Nginx伺服器的使用與反向代理負載均衡Nginx伺服器負載
- nginx反向大理和負載均衡以及高可用Nginx負載
- 圖解Nginx,系統架構演變 + Nginx反向代理與負載均衡圖解Nginx架構負載
- centos7下配置nginx反向代理負載均衡叢集CentOSNginx負載
- Nginx反向代理+負載均衡簡單實現(https方式)Nginx負載HTTP
- nginx反向代理負載均衡與動靜頁面分離Nginx負載
- Nginx 全模組安裝及匹配方式、反向代理和負載均衡配置Nginx負載
- 誰說前端不需要懂-Nginx反向代理與負載均衡前端Nginx負載
- 在windows環境下 nginx + .net core 3.1 實現反向代理和負載均衡WindowsNginx負載
- 在Linux中,nginx反向代理和負載均衡實現原理是什麼?LinuxNginx負載
- Nginx+Tomcat部署負載均衡NginxTomcat負載
- 如何使用 Weave 以及 Docker 搭建 Nginx 反向代理/負載均衡伺服器DockerNginx負載伺服器
- NGINX 負載均衡Nginx負載
- 【Nginx】負載均衡Nginx負載
- nginx負載均衡Nginx負載
- Nginx代理功能與負載均衡詳解Nginx負載
- 代理與反向代理、負載均衡和快取負載快取
- nginx之 nginx-1.9.7 + tomcat-8.5.15 反向代理+應用負載均衡 安裝配置NginxTomcat負載
- Nginx負載均衡模式Nginx負載模式
- Nginx--負載均衡Nginx負載
- nginx 負載均衡搭建Nginx負載
- Nginx負載均衡策略Nginx負載
- 解析 Nginx 負載均衡Nginx負載
- nginx反向代理+快取開啟+url重寫+負載均衡(帶健康探測)的部署記錄Nginx快取負載
- nginx反向代理負載均衡帶你突破單臺伺服器的瓶頸Nginx負載伺服器