有两个jsp应用,本地访问地址如下
http://127.0.0.1:8080/app1
http://127.0.0.1:8080/app2
通过下面的配置可以实现 http://domain.com/app1 和 http://domain.com/app2 的访问
server { listen 80; server_name domain.com; charset utf-8; location /{ proxy_pass http://127.0.0.1:8080/; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
现在想用两个域名来访问这两个应用
通过 http://app1.domain.com 来访问 http://127.0.0.1:8080/app1
通过 http://app2.domain.com 来访问 http://127.0.0.1:8080/app2
配置如下
server { listen 80; server_name app1.domain.com; charset utf-8; location /{ proxy_pass http://127.0.0.1:8080/app1; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } server { listen 80; server_name app2.domain.com; charset utf-8; location /{ proxy_pass http://127.0.0.1:8080/app2; proxy_redirect off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
结果只能显示首页,静态资源都无法加载
#我感觉应该这么写可是有语法错误 if ($uri ^/$){proxy_pass http://127.0.0.1:8080/app1;} if ($uri ^/app1){proxy_pass http://127.0.0.1:8080/$request_uri;}
所以到底应该应该如何配置?
大致思路就是把 .domain.com/ 都转发到 http://127.0.0.1:8080/$1/$2
一周热门 更多>