【发布时间】:2018-06-11 01:17:28
【问题描述】:
我正在运行一个网站,该网站由 8080 端口上的 docker 中的 API 和包含前端 react 应用程序的静态文件夹组成。
API 位于/api
我正在尝试配置 NginX 以正确地为该配置提供服务,但我无法弄清楚如何让两者都工作。
如果我像这样设置我的default:
server {
root /var/www/html;
server_name DOMAIN; # managed by Certbot
location @nodeapp {
# Redirect to the api
proxy_pass http://localhost:8080;
}
location / {
# Map all the routes to the index.html
try_files $uri @nodeapp;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/DOMAIN/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/DOMAIN/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
然后所有内容都被重定向到我的 API,如果没有明确指定(例如转到 https://host/index.html),则不会传递静态内容
如果我添加 try_files $uri $uri/ @nodeapp; 以将根文件夹作为目录提供服务,则提供索引,但我无法再访问 API,它始终为 react 应用提供服务
我也尝试添加
location /api/ {
proxy_pass http://localhost:8080
}
但没有区别
我做错了什么?
【问题讨论】: