【发布时间】:2020-06-30 05:12:52
【问题描述】:
背景/目标:
大家好,第一次发帖!
我目前正在尝试配置 NGINX,以便它 -
- 在特定路由被命中时提供 React 应用程序,例如/auth/
- 将 /api 路由上的所有流量代理到 Node 后端
- 在所有其他路线上为 Wordpress 网站提供服务
问题: 我在我的 NGINX 配置文件中定义了一个 /auth 位置块,它指向文件夹 /home/ubuntu/app/client/build 中包含的 React 应用程序。
如果我访问 /auth 路由,NGINX 会正确地为 React 应用程序提供服务。
但是,当我向 嵌套路由(例如 /auth/login)发出 HTTP 请求时,我收到 404 错误。
我已尝试剥离 NGINX 配置文件以仅包含 /auth 位置块,但问题仍然存在。因此,我认为这与文件中的其他设置无关。
指定确切的路线不是一个可行的解决方案,因为我尚未添加的许多其他路线都具有动态嵌套值,例如/users/someuniqueid。
配置文件
希望以下内容能阐明我做错了什么。请注意,出于隐私原因,我已删除服务器名称,因此请不要假设我使用了该实际名称:)
server {
listen 80;
server_name myipaddress;
root /home/ubuntu/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location /css {
alias /home/ubuntu/app/client/build/css;
}
location /media {
alias /home/ubuntu/app/client/build/media;
}
location /static {
alias /home/ubuntu/app/client/build/static;
}
location /assets {
alias /home/ubuntu/app/client/build/assets;
}
location /auth {
alias /home/ubuntu/app/client/build;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock; #Ubuntu 17.10
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/myurl.io/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/myurl.io/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhusername.pem; # managed by Certbot
}
【问题讨论】:
-
它是否使用 docker 运行,ngix 在 docker 上运行,节点应用程序也在 docker 中运行?
-
我没有使用容器。目前它都在一个 Ubuntu EC2 实例上运行。
标签: node.js reactjs wordpress nginx