nginx 发现代理在实际运用中非常的广泛,下面记载一个nginx的反向代理实例,可以参考一下实例学习nginx反向代理哦!
server {
listen 443;
ssl on;
ssl_certificate /usr/local/nginx/conf/cert/test/www.pem;
ssl_certificate_key /usr/local/nginx/conf/cert/test/www.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
server_name www.test.com;
access_log /home/logs/test.www.access.log;
include /etc/nginx/default.d/*.conf;
root /home/www/test/public;
index index.php;
location = / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* (\/app|\/ios|\/com|\/news|\/topic|\/rank|\/down|\/footer|\/xml|\/favicon|\/zjbb|\/xxbb|\/xbbb|\/static|\/uploads|\/hits\/|\/pks\/) {
try_files $uri $uri/ /index.php?$query_string;
}
location / {
charset utf-8;
proxy_redirect off;
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_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass https://xx.xx.xx.xx/;
}
location = /portal.php {
charset utf-8;
proxy_redirect off;
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_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass https://xx.xx.xx.xx/;
}
location = /forum.php {
charset utf-8;
proxy_redirect off;
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_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass https://xx.xx.xx.xx/;
}
location = /search.php {
charset utf-8;
proxy_redirect off;
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_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass https://xx.xx.xx.xx/;
}
location = /misc.php {
charset utf-8;
proxy_redirect off;
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_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass https://xx.xx.xx.xx/;
}
location = /home.php {
charset utf-8;
proxy_redirect off;
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_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass https://xx.xx.xx.xx/;
}
location ~ \.php$ {
root /home/www/test/public;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
结束语
本文有任何错误,或有任何疑问,欢迎留言说明。
网友最新评论