🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
~~~ server { listen 80 default_server; server_name _; index index.html index.htm index.php; root /home/wwwroot; charset utf -8; #error_page 404 /404.html; # 拒绝访问特定目录中的PHP文件 #location / { deny all; } location / { echo "localhost"; } location /myproxy { proxy_pass http://192.168.0.12:80; } } } ~~~ 本机192.168.0.2和192.168.0.12两台服务器 本机浏览器访问http://localhost 输出localhost 本机访问http://localhos/myproxy时,则转发到另一台服务器,即http://192.168.0.12:80/myproxy 如果想要访问http://localhos/myproxy时转到http://192.168.0.12:80呢 ``` location /myproxy/ { proxy_pass http://192.168.0.12:80/; } ``` 有起了一个http://192.168.0.12:81的项目 ``` location /myproxy/ { proxy_pass http://192.168.0.12:80/; } location /myproxy2/ { proxy_pass http://192.168.0.12:81/; } ``` http://localhos/myproxy/ http://localhos/myproxy2/ ## ****负载均衡**** ~~~ http { upstream group1{ server 192.168.0.12:80 weight=10; server 192.168.0.12:81 weight=1; } server { listen 80; server_name localhost; default_type text/html; location /myproxy/ { proxy_pass http://group1/; } } } ~~~ 访问http://localhos/myproxy/时根据权重显示92.168.0.12:80 和92.168.0.12:81的内容