将Nginx配置为从根目录中的某个位置为节点js应用程序提供服务

将Nginx配置为从根目录中的某个位置为节点js应用程序提供服务,nginx,nginx-location,Nginx,Nginx Location,我正在尝试为一个Node JS应用程序提供服务,与一些已经运行且仅提供静态内容的静态站点一起提供服务(/insta app是其中一个应用程序,另一个nginx文件带有另一个服务器块,用于位于不同子域上的其他应用程序)。当我导航到URL/nodejsap时,我成功地获得了server.js应用程序。问题是,该应用程序所需的所有静态内容都没有得到提供,而是以404(图像、js文件和css)的形式出现。我为nodejsapp/dist编写了一个位置块,其中存在静态内容,但这并没有解决问题。内容由Han

我正在尝试为一个Node JS应用程序提供服务,与一些已经运行且仅提供静态内容的静态站点一起提供服务(/insta app是其中一个应用程序,另一个nginx文件带有另一个服务器块,用于位于不同子域上的其他应用程序)。当我导航到URL/nodejsap时,我成功地获得了server.js应用程序。问题是,该应用程序所需的所有静态内容都没有得到提供,而是以404(图像、js文件和css)的形式出现。我为nodejsapp/dist编写了一个位置块,其中存在静态内容,但这并没有解决问题。内容由Handlebar模板请求,该模板被成功调用,并位于根目录的views文件夹中。我在ubuntu服务器上运行整个程序,节点应用程序通过pm2运行,当我请求curl localhost:3000时,pm2工作正常。如何将静态内容导入服务器

Nginx服务器块:

 server {
        listen 443 ssl default_server;

        root /var/www;
        index index.html index.htm server.js;

        server_name uat.com www.uat.com;

        ssl on;
        ssl_certificate /etc/letsencrypt/live/uat.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/uat.com/privkey.pem;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ /.well-known{
                allow all;
        }

        location /insta-app{
                alias /var/www/insta-app/html;
                allow all;
        }

        location /nodeJsApp{
               proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-NginX-Proxy true;
                proxy_pass http://127.0.0.1:3000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $proxy_host;
                proxy_cache_bypass $http_upgrade;
                proxy_redirect off;
        }

         # attempt to serve the static content of the app
        location /nodeJsApp/dist{ 
                root /var/www/sydney-sevens/dist;
                try_files $uri $uri/ =404;
       }
}

在浏览器中打开应用程序时,URL请求是什么?NGINX在错误日志中报告了什么?我猜URL请求没有达到您期望的位置块。嗨,Alan,请求是。这是请求头:
Accept:text/html、application/xhtml+xml、application/xml;q=0.9,图像/webp,*/*;q=0.8接受编码:gzip,deflate,sdch,br接受语言:en-US,en;q=0.8缓存控制:无缓存连接:保持活动主机:uat.com Pragma:无缓存升级不安全请求:1用户代理:Mozilla/5.0(Macintosh;Intel Mac OS X 10_11_2)AppleWebKit/537.36(KHTML,如Gecko)Chrome/55.0.2883.95 Safari/537.36
Nginx erro日志显示
26159\0:服务器名称“www.uat.com/sydney sevens”在/etc/nginx/sites中启用了可疑符号/default:79
发布404的实际请求,它应该在浏览器的控制台窗口中。