我的 Nginx 安装并运行,下面是配置/etc/nginx/nginx.conf
,我要全部转发/api/*
到我的 tomcat 服务器,该服务器在同一服务器上的端口 9100 上运行(类型http://myhost:9100/api/apps
有效),否则,在“/usr/share/nginx/html”下提供静态文件。现在我输入http://myhost/api/apps
给出 404。这里有什么问题?
upstream myserver {
server localhost:9100 weight=1;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location ^~ /api/ {
proxy_pass http://myserver/;
}
location / {
}
}
The proxy_pass
声明可能可选地在将 URI 传递到上游之前修改 URI。看这个文件 http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass了解详情。
在这种形式中:
location ^~ /api/ {
proxy_pass http://myserver/;
}
The URI /api/foo
被传递给http://myserver/foo
.
通过删除尾随/
来自proxy_pass
陈述:
location ^~ /api/ {
proxy_pass http://myserver;
}
The URI /api/foo
现在传递给http://myserver/api/foo
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)