我创建了一个使用nuxtjs前端和strapi后端的网站。部署到VPS后,我无法使bandi路由正常工作。我在互联网上阅读了有关此内容的多则帖子,并关注了the official documentation about nginx proxying,但没有成功。
路径:/etc/nginx/sites-available/example.com
fn new(cards: Vec<Card<'t>>) -> Self {
CardsConnection {
edges: cards
.into_iter()
.map(|c| CardsConnectionEdge {
cursor: c.id.clone(),
node: c,
})
.collect::<Vec<CardsConnectionEdge>>(),
}
}
路径:backend / config / server.js
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;
}
}
访问example.com将按预期显示前端。访问example.com/strapi可以找到以下站点:
点击“打开公告”按钮,将我带到example.com/admin,该页面返回我的404前端错误页面。
我将非常感谢您提供的任何帮助。
答案 0 :(得分:0)
我曾经遇到过同样的问题
现在我使用子域配置来避免这些问题
好多了
这是我的配置
NGINX
server {
listen 80;
server_name example.com www.example.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Client-IP $remote_addr;
proxy_set_header X-Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
client_max_body_size 0;
charset utf-8;
location / {
proxy_pass http://webapp:9984;
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;
}
}
server {
listen 80;
server_name api.example.com www.api.example.com;
location / {
proxy_pass http://backend:13131;
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;
}
}
STRAPI
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
url: `http://api.encuestop.com/`,
admin: {
auth: {
secret: env('ADMIN_JWT_SECRET', '----'),
},
},
});