Я думал, что смогу получить доступ к индексной странице реакции с localhost: 80 и apis с localhost / api / example, но вместо этого вижу ошибку «404 страница не найдена» для этих страниц.
ОднакоЯ могу отобразить индексную страницу реагирования с localhost: 3000, а URL-адреса API с localhost: 5000 / api / example.
nginx.conf
events {
worker_connections 1024;
}
http {
# include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream nodeweb {
server localhost:3000;
}
upstream flaskapp {
server localhost:5000;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# try_files $uri /index.html; -> adding this line gives 500 Internal Server Error
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
# enable EventSource
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_buffering off;
proxy_cache off;
proxy_pass http://nodeweb$is_args$args;
}
location ~ /api/(?<section>.*) {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_buffering off;
proxy_set_header Host $host;
proxy_pass http://flaskapp/$section$is_args$args;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}