nginx配置如下:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#gzip on;
upstream web1 {
server 192.168.1.102:8099;
}
upstream web2 {
server 192.168.1.102:8099;
}
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /api/web1/ {
proxy_pass http://web1/Shopping/web1.html;
}
location /auth {
internal;
proxy_set_header Host $host;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_pass http://192.168.1.102:9099/Shopping;
}
#location @error401 {
#add_header Set-Cookie "NSREDIRECT=$scheme://$http_host$request_uri;Path=/";
#return 302 http://192.168.1.102:9099/index.html;
#}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
我们的真正访问地址为:http://192.168.1.102:8099/Shopping/web1.html
访问效果如下:
![](https://i-blog.csdnimg.cn/blog_migrate/973fba560508c7b38ba4b91499bd18c8.png)
而我们访问的是nginx的地址:http://192.168.1.102/api/web1/,它根据我们的方向代理配置能达到同样的访问效果:
![](https://i-blog.csdnimg.cn/blog_migrate/e77f8a9a3e9113b0f482ed5ca7d201be.png)