我有一个NGINX配置文件,可以通过开发服务器和静态文件为网站提供服务。
静态-> http://localhost:8080
开发dev服务器-> http://localhost:8080/dev
还有几个其他服务,我绑定到不同的位置指令。
下面是配置文件的一个片段。
...
upstream qgis {
server qgis-spcluster_server:80;
}
...
server {
listen 8080;
server_name localhost;
location / {
root /usr/share/nginx/html/build;
index index.html index.htm;
auth_basic "Zugangskontrolle";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location /dev/ {
proxy_pass http://web_app/;
auth_basic "Zugangskontrolle";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location /static/ {
proxy_pass http://web_app/static/;
}
location /qgis/ {
proxy_pass http://qgis/;
}
location /apex/ {
proxy_pass http://apex/apex/;
auth_basic "off";
}
...在打开URL以获取静态文件之前,所有操作都与预期的一样。之后,所有其他URL都会导致静态文件。
对我来说,一切看起来都很好,但确实有些不对劲。
Basic_Auth会产生另一个意想不到的行为。
所以现在我有点不知道如何解决这个问题。
发布于 2017-07-25 12:33:21
我现在试了好几件事,但都没什么好用的。因此,我决定为所有位置指令创建第二个服务器块,这些指令在我当前的设置中存在问题。
也许这不是最好的解决方案,因为我仍然不知道为什么我会遇到这些问题。但现在起作用了,这对我来说很重要。
发布于 2017-07-25 08:40:00
请从您的位置指令中删除尾随的/,或者在访问它们时提供/。
Nginx寻找最长的前缀匹配位置。当您访问http://localhost:8080/apex时,它被路由到/,因为/apex/不是/apex的前缀
location的文档是这里
https://stackoverflow.com/questions/45297394
复制相似问题