Nginx——域名|端口|目录请求转发配置DEMO
生活随笔
收集整理的這篇文章主要介紹了
Nginx——域名|端口|目录请求转发配置DEMO
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、域名轉發?
upstream tomcat_taobao {server 192.168.71.129:8081; #訪問的tomcat的IP }server {listen 80; #監聽的對外端口server_name www.taobao.com; #域名location / {proxy_pass http://tomcat_taobao; #必須與服務器上對應的tomcat的upstream tomcat_taobao相對應index index.html index.htm;} }upstream tomcat_sina {server 192.168.71.129:8082; #訪問的tomcat的IP }server {listen 80;#監聽的對外端口server_name www.sina.com;#域名location / {proxy_pass http://tomcat_sina; #必須與服務器上對應的tomcat的upstream tomcat_sina相對應index index.html index.htm;} }?2、端口轉發
server {listen 80;autoindex on;server_name www.port.com;access_log c:/access.log combined;index index.html index.htm index.jsp index.php;#error_page 404 /404.html;if ( $query_string ~* ".*[\;'\<\>].*" ) {return 404;}location / {proxy_pass http://127.0.0.1:8080;add_header Access-COntrol-Allow-Origin *;} }3、目錄轉發?
server {listen 80;autoindex on;server_name www.stzg.com;access_log c:/access.log combined;index index.html index.htm index.jsp index.php;#error_page 404 /404.html;if ( $query_string ~* ".*[\;'\<\>].*" ) {return 404;}location / {root C:\file\img; # \是Windows /是Linuxadd_header Access-Control-Allow-Origin *;} }4、負載均衡
//簡單的負載均衡,nginx支持ip_hash等分流,也支持插件自定義規則分流 upstream model{ server 127.0.0.1:8080server 127.0.0.1:8081server 127.0.0.1:8082 } server { listen 80;server_name localhost;location / { proxy_pass model; proxy_redirect default; } }參考文章
https://blog.csdn.net/weixin_44550490/article/details/93369580
https://blog.csdn.net/kuaizisong/article/details/82790745
https://www.cnblogs.com/meetzy/p/8565507.html
https://www.jianshu.com/p/38810b49bc29
https://my.oschina.net/u/3703522/blog/1603984
總結
以上是生活随笔為你收集整理的Nginx——域名|端口|目录请求转发配置DEMO的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx+PHP-FPM——Nginx
- 下一篇: Nginx——反向代理路径重写重定向实践