【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入門(2)反向代理和負載均衡Nginx負載
- docker下nginx反向代理和負載均衡配置DockerNginx負載
- nginx反向代理和負載均衡策略實戰案例Nginx負載
- Nginx負載均衡反向代理伺服器Nginx負載伺服器
- nginx面試題-nginx負載均衡與正反向代理Nginx面試題負載
- nginx配置web服務|反向代理|負載均衡NginxWeb負載
- 介紹下Nginx 反向代理與負載均衡Nginx負載
- 做了反向代理和負載均衡的nginx配置檔案簡單示例(nginx.conf) HTTP負載均衡/TCP負載均衡負載NginxHTTPTCP
- Nginx搭建反向代理負載均衡和web快取伺服器Nginx負載Web快取伺服器
- Nginx伺服器的使用與反向代理負載均衡Nginx伺服器負載
- nginx反向大理和負載均衡以及高可用Nginx負載
- 圖解Nginx,系統架構演變 + Nginx反向代理與負載均衡圖解Nginx架構負載
- centos7下配置nginx反向代理負載均衡叢集CentOSNginx負載
- Nginx+Tomcat部署負載均衡NginxTomcat負載
- 在Linux中,nginx反向代理和負載均衡實現原理是什麼?LinuxNginx負載
- 誰說前端不需要懂-Nginx反向代理與負載均衡前端Nginx負載
- Nginx 全模組安裝及匹配方式、反向代理和負載均衡配置Nginx負載
- 在windows環境下 nginx + .net core 3.1 實現反向代理和負載均衡WindowsNginx負載
- nginx負載均衡Nginx負載
- NGINX 負載均衡Nginx負載
- 【Nginx】負載均衡Nginx負載
- 理解 Nginx HTTP 代理, 負載均衡, Buffering, CachingNginxHTTP負載
- 代理與反向代理、負載均衡和快取負載快取
- Nginx負載均衡模式Nginx負載模式
- nginx反向代理、負載均衡配置與linux環境下的安裝及通過ip和域名訪問nginxNginx負載Linux
- nginx反向代理負載均衡帶你突破單臺伺服器的瓶頸Nginx負載伺服器
- nginx部署基於http負載均衡器NginxHTTP負載
- Nginx負載均衡高可用Nginx負載
- 012.Nginx負載均衡Nginx負載
- Nginx負載均衡詳解Nginx負載
- nginx實現負載均衡Nginx負載
- Nginx正向代理和反向代理配置Nginx
- 秒懂負載均衡與反向代理負載
- Nginx反向代理Nginx
- nginx 反向代理Nginx
- nginx+php 實現代理與負載均衡 (1臺nginx,2臺php)NginxPHP負載
- nginx Win下實現簡單的負載均衡(1)nginx搭建部署Nginx負載
- 負載均衡之--Nginx、LVS、HAProxy負載Nginx