我的nginx.conf中有一条规则不起作用,我也不知道为什么。根据文件,它应该能工作。配置的一部分如下所示。
端口8100的第一个规则工作,并将调用http://example.com/api/domains重定向到https://localhost:8181/oan/resources/domains。
# Working
server {
listen 8100 default_server;
server_name example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
root /var/www/html/example;
location /api {
proxy_pass https://localhost:8181/oan/resources; break;
}
# For ReactJS to handle routes
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ / break;
}
}
}
# Not working
server {
listen 8200;
server_name api.example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
location / {
proxy_pass https://localhost:8181/oan/resources; break;
}
}对端口8200:http://api.example.com:8200/domains的最后一次调用应该重定向到:https://localhost:8181/oan/resources/domains,但不会这样做。
这个配置有什么问题,我如何获得端口8200上的最后一个规则,做正确的事情,总是重定向到https://localhost:8181/oan/resources/$uri
发布于 2019-11-18 10:27:31
当您在前缀位置块中使用带有可选URI的proxy_pass时,Nginx将执行一个直接的文本替换来转换请求的URI。
在您的示例中,前缀位置值为/,可选URI值为/oan/resources。因此,请求的/foo URI将被转换为/oan/resourcesfoo。
为了进行正确的操作,这两个值都应该以/结尾,也不能以/结尾。
例如:
location / {
proxy_pass https://localhost:8181/oan/resources/;
}详情请参见本文件。
https://stackoverflow.com/questions/58609618
复制相似问题