我一直在尝试配置后端 NodeJS 服务器 (ExpressJS) 以与 Nginx 一起使用,但遇到了一些困难。我目前正在运行安装了 Ubuntu 20.04 的 DigitalOcean droplet。
以下是我所做的:
- 安装并配置Nginx,设置适当的文件夹和配置文件;
- 使用 Let's Encrypt 为域名生成并放置 SSL;
- 用于
forever start server.js
让 Node 应用程序作为进程在后台运行; - 添加了在端口 60000 上运行的
ufw
适当端口规则。server.js
我尝试了很多不同的配置,但都无济于事,在阅读文档后,我尝试了一些自己的配置,但这是我现在所拥有的,它基于回复中提出的工作配置这里,在其他地方被引用为成功的配置:
GNU nano 4.8 domain.com
server {
root /var/www/example.com/html;
index index.html index.htm index.nginx-debian.html;
server_name example.com www.example.com;
listen [::]:443 SSL ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
listen 80;
listen [::]:80;
ssl_certificate /etc/letsencrypt/live/example.com/fullcha>
ssl_certificate_key /etc/letsencrypt/live/example.com/pri>
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Ce>
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Cert>
location / {
proxy_pass http://localhost:60000;
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;
try_files $uri $uri/ /index.html;
}
}
该网站运行正常,启用了 SSL,等等。但有一页“Inventory”向 Express 服务器发送命令,在页面加载时运行数据库查询。在检索数据之前(正如我所编码的),一直显示“正在加载...”,然后就挂在那里了。Express 服务器根本没有收到任何信息,因为如果收到了,服务器端控制台会显示一条消息,但事实并非如此。我 100% 确定这是 Nginx 配置的问题。
有什么想法吗?配置有问题吗?
编辑:浏览器控制台显示四条消息:
Blocked loading mixed active content “http://IPADDR:60000/”
The resource from “https://example.com/static/css/main.3a7e5913.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
Source map error: Error: request failed with status 404
Resource URL: https://example.com/static/css/main.3a7e5913.css
Source Map URL: main.3a7e5913.css.map
Source map error: Error: request failed with status 404
Resource URL: https://example.com/static/js/main.0df87846.js
Source Map URL: main.0df87846.js.map