【发布时间】:2022-03-22 00:29:12
【问题描述】:
我创建了一个使用nuxtjs 前端和strapi 后端的网站。部署到 VPS 后,我无法让strapi 路由工作。我在互联网上阅读了多篇关于此的帖子并关注了the official documentation about nginx proxying,但没有成功。
路径:/etc/nginx/sites-available/example.com
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
# Strapi API and Admin
location /strapi/ {
rewrite ^/strapi/(.*)$ /$1 break;
proxy_pass http://127.0.0.1:1337;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
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 $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass_request_headers on;
}
}
路径:backend/config/server.js
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: 'http://example.com/strapi',
});
访问 example.com 会按预期显示前端。访问 example.com/strapi 会显示以下站点:
单击“Open admnistration”按钮将我带到 example.com/admin,它会返回我的 404 前端错误页面。
我会非常感谢任何形式的帮助。
【问题讨论】:
-
您好,example.com/strapi/admin 是什么?你的配置看起来不错 (the new documentation is online)
标签: nginx routes nginx-config strapi