我让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;
}
}
}