proxying nginx Express - 404 on static files

后端 未结 1 1024
轮回少年
轮回少年 2021-01-06 15:52

Static files of expressjs app perfectly working when I browse the site from my server ip:port, but when the app serves from nginx, static file gives 404 . Here is my nginx c

相关标签:
1条回答
  • 2021-01-06 16:15

    Although express.js has built in static file handling through some connect middleware, you should never use it. Nginx can do a much better job of handling static files and can prevent requests for non-dynamic content from clogging node processes. here is an example of doing this:

    http {
        ...
        server {
            ...
            location ~ ^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/|robots.txt|humans.txt|favicon.ico) {
              root /home/ubuntu/expressapp/public;
              access_log off;
              expires max;
            }
            ...
        }
    }
    
    0 讨论(0)
提交回复
热议问题