Nginx没有代理到节点后端

时间:2019-08-21 18:52:20

标签: express nginx proxy nginx-location nginx-config

我让React应用程序在Nginx上运行,而后端应用程序在Nodejs(在另一个端口8080上运行),路由的模式为“ /org-metadata/**, /proxy-api/**, /node-api/**”。

我正在尝试将nginx代理到运行在8080上的nodejs,但是它没有到​​达后端。然后nginx会给出503 Service Unavailable响应,有时还会给出200响应,您需要启用JavaScript才能运行此应用。

请问我在哪里缺少任何东西?

下面是我的nginx.conf文件:

worker_processes auto;

events {
    worker_connections 8000;
    multi_accept on;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    server {
        # listen on port 80
        listen 80;

        # where the root here
        root /var/www;
        # what file to server as index
        index index.html index.htm;

        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to redirecting to index.html
            try_files $uri $uri/ /index.html;
        }

        # Javascript and CSS files
        location ~* \.(?:css|js)$ {
            try_files $uri =404;
            expires 1y;
            access_log off;
            add_header Cache-Control "public";
        }

        location ~ (proxy-api|org-metadata|node-api) {
            try_files $uri @nodejs;
        }

        location @nodejs {
            proxy_pass http://nodejs:8080;
            add_header X-Frame-Options "SAMEORIGIN" always;
            add_header X-XSS-Protection "1; mode=block" always;
            add_header X-Content-Type-Options "nosniff" always;
            add_header Referrer-Policy "no-referrer-when-downgrade" always;
            add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
        }
    }
}

0 个答案:

没有答案