我有以下文件:
~/app1/index.html
~/app2/index.html
~/app3/index.html
和nginx配置:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
server_name example.org;
location / {
try_files $uri $uri/ =404;
}
location /app1/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8081;
rewrite ^/app1(.*) /$1 break;
}
location /app2/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8082;
rewrite ^/app2(.*) /$1 break;
}
location /app3/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8083;
rewrite ^/app3(.*) /$1 break;
}
}
如何让http://example.org/app1
返回~/app1/index.html
中的文件?当前,它重定向回到根http://example.org
(尽管可以直接导航到http://example.org/app1/index.html
)。