我在研究数字海洋水滴。
https://docs.strapi.io/developer-docs/latest/setup-deployment-guides/deployment/optional-software/nginx-proxy.html#strapi-server
我已经尝试按照这个指南几个小时了,但我就是不能让它工作。当我试图连接,我得到502坏网关,不知道这意味着什么。当我只是8011端口启用通过防火墙和连接到端口直接通过DNS,它工作正常。
做nginx -t
说语法没问题,我试过很多次重启服务,键都能用。/etc/nginx/conf.d/upstream.conf
:
# Strapi server
upstream strapi {
server 127.0.0.1:8011;
}
etc/nginx/sites-available/default
:
server {
# Listen HTTP
listen 80;
server_name losslessly-api.djkato.net;
# Redirect HTTP to HTTPS
return 301 https://$host$request_uri;
}
server {
# SSL configuration
#
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/nginx/certificate/losslessly-api.djkato.net.crt;
ssl_certificate_key /etc/nginx/certificate/losslessly-api.djkato.net.key;
server_name losslessly-api.djkato.net;
# Proxy Config
location / {
proxy_pass http://strapi;
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;
}
}
./config/server.js
:
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 8011),
url: 'https://losslessly-api.djkato.net',
});
sudo ufw status
:
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
8011/tcp DENY Anywhere
Nginx HTTP ALLOW Anywhere
Nginx HTTPS ALLOW Anywhere
8011 DENY Anywhere
Nginx Full ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
8011/tcp (v6) DENY Anywhere (v6)
Nginx HTTP (v6) ALLOW Anywhere (v6)
Nginx HTTPS (v6) ALLOW Anywhere (v6)
8011 (v6) DENY Anywhere (v6)
Nginx Full (v6) ALLOW Anywhere (v6)
1条答案
按热度按时间os8fio9y1#
我做了一个
netstat -tulpn | grep LISTEN
,发现我的应用程序没有监听本地主机,而是监听了公共IP。查看我的strapis.env文件,我意识到我设置了HOST:{public ip}
,而不是APP_URL:{public ip}
,这意味着我的上游连接在错误的IP上。修复我的env文件解决了这个问题。