我需要配置nginx配置,以便网站nuxt
可以在通常的地址访问,管理面板strapi
地址/api
。网站本身工作并接收数据,但不接收来自strapi
的uploads
文件夹中的图像。
此外,我不能进入strapi
管理面板,因为strapi
主页是受欢迎的,然后有一个重定向到/admin
页面,我没有。我已经尝试了很多配置变化,但我没有得到它。
我需要做什么?/etc/nginx/conf.d/upstream.conf
upstream strapi {
server localhost:1337;
}
upstream nuxt {
server localhost:3000;
}
nuxt.config.ts
vite: {
server: {
hmr: {
protocol: "wss",
clientPort: 443,
path: "hmr/",
},
},
},
confing
server {
listen 80;
listen 0.0.0.01:80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl http2;
listen 0.0.0.01:443 ssl http2;
server_name www.example.com;
return 301 https://example.com$request_uri;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
include snippets/ssl-params.conf;
}
server {
listen 443 ssl http2;
listen 0.0.0.01:443 ssl http2;
server_name example.com;
root /var/www/example.com/client;
index index.mjs index.html index.xml;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
include snippets/ssl-params.conf;
rewrite ^/(.*) /$1 break;
location / {
proxy_set_header Host $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_redirect off;
proxy_buffering on;
proxy_cache_valid 200 1d;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_pass http://nuxt;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
include proxy_params;
}
location /api/ {
rewrite ^/api/(.*)$ /$1 break;
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;
proxy_pass http://strapi;
include proxy_params;
}
location /_nuxt/hmr/ {
proxy_pass http://localhost:24678;
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;
}
}
1条答案
按热度按时间apeeds0o1#
先读这个
Strapi仅适用于子域
strapi.exaple.com
或example.com/strapi
。按照指南,您需要创建一个URL,以打开管理面板
strapi
。我从指南中排除了
serveAdminPanel: false
线。字符串
url: 'http://yourbackend.com
必须包含strapi
前端部分的路径.env
文件中所有站点的地址都应该是https
而不是http
,这在应用程序的前端部分和后端部分都是必要的