Express - Nginx führt das Knotenprogramm aus, der Routing-Sprung beträgt 404 und statische Dateien können normal geladen werden
PHP中文网
PHP中文网 2017-05-24 11:32:53
0
2
1038
Der

Nginx-Konfigurationscode sieht so aus

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                root /home/ubuntu/card/public;
                try_files $uri $uri/ =404;
                proxy_pass http://127.0.0.1:3000;
        }
        
}

Mit dem Node-Programm selbst gibt es kein Problem

PHP中文网
PHP中文网

认证高级PHP讲师

Antworte allen(2)
伊谢尔伦

我的理解是try_files 如果不成功,应该让express服务器尝试响应

location / {

            root /home/ubuntu/card/public;
            try_files $uri $uri/ @proxy;
    } 

location @proxy {

proxy_pass http://127.0.0.1:3000;  

}

漂亮男人

假设你的目录/home/ubuntu/card/public下有个叫uploads的文件夹,nginx配置如下

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    server_name _;

    location / {
        proxy_pass http://127.0.0.1:3000;
    }

    location /uploads {
        root /home/ubuntu/card/public/;
        index index.html index.htm index.nginx-debian.html;
        try_files $uri $uri/ =404;
    }
}

那么访问http://localhost/会跳到nodejs,http://localhost/uploads/会访问/home/ubuntu/card/public/uploads下的静态文件。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!