location /X { proxy_pass http://localhost:8070/X }
location /Y {
proxy_pass http://localhost:8070/Y } location /Z { proxy_pass http://localhost:8070/Z }
能不能用一个表达式就代替这些地址
如果你只是原样转发请求的话,可以尝试下面的配置:
location ~* ^(.*) {
proxy_pass http://127.0.0.1:9000; # 你要转发的上游服务器
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
}
location ^~ /api/ { root html; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://localhost:8001/api/; proxy_redirect default; } location ^~ /admin_api/ { rewrite ^/admin_api/?$ /api/$1 redirect; root html; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://localhost:8002/api/; proxy_redirect default; } 我这样配置过,一个项目请求了多个后台,然后改api前缀进行区分
location / { try_files $uri $uri/ /index.html; }