简体   繁体   English

Express 和 Nginx 对路由的争论

[英]Express and Nginx figthing over routing

So i have a strange configuration that i need until i get to refactor a project later this year.所以我需要一个奇怪的配置,直到我在今年晚些时候重构一个项目。

it is a static index.html landing page served with a location root "/" by NGINX.它是一个静态的 index.html 登陆页面,由 NGINX 提供一个位置根“/”。

i have a slash location like so:我有一个像这样的斜线位置:

    location /channel/ {
        proxy_pass http://node_server:5000/;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Ssl on;
        proxy_cache_bypass $http_upgrade;
    }

that express.js then handles.然后 express.js 处理。 Express just serves a static folder with auto-generated content that a user can then navigate around in. Express 只是提供一个静态文件夹,其中包含自动生成的内容,然后用户可以在其中导航。

It works well in the sense that any appending slashes like:它在任何附加斜杠的意义上都很有效:

/channel/open/ /频道/打开/

but ONLY if i have a trailing slash after "open".但前提是我在“打开”后有一个斜杠。 If i leave it out then NGINX will throw a "404 Not Found", if i keep it in, it works as intended.如果我忽略它,那么 NGINX 将抛出“404 Not Found”,如果我保留它,它会按预期工作。

The thing is that a user should be able to click on a folder in the static served directory to traverse a file structure, and the way that works in a browser is that it does not append a trailing slash to a directory name when clicked, so NGINX then throws the "404".I have tried a NPM package called 'express-slash' but that did not solve the issue.问题是用户应该能够单击静态服务目录中的文件夹来遍历文件结构,而在浏览器中的工作方式是单击时不会在目录名称后附加斜杠,因此NGINX 然后抛出“404”。我尝试了一个名为“express-slash”的 NPM 包,但这并没有解决问题。

i was hoping someone here had some suggestions on what i could try out next?我希望这里有人对我接下来可以尝试的内容提出一些建议?

Details about trailing slash behavior can be found here: https://serverfault.com/questions/607615/using-trailing-slashes-in-nginx-configuration可以在此处找到有关尾随斜杠行为的详细信息: https : //serverfault.com/questions/607615/using-trailing-slashes-in-nginx-configuration

But if your goal is to configure NGINX to allow directory traversal, you may be looking for the autoindex directive: http://nginx.org/en/docs/http/ngx_http_autoindex_module.html但是如果你的目标是配置 NGINX 以允许目录遍历,你可能正在寻找autoindex指令: http : //nginx.org/en/docs/http/ngx_http_autoindex_module.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM