【发布时间】:2021-09-07 07:15:24
【问题描述】:
我正在尝试使用 Angular 和 NestJs 在 Ubuntu 远程服务器上使用 Nginx 部署我的 web 应用程序。 我让前端在https://ikse.fransenit.nl/products 上工作,但无法让后端工作。它在本地运行良好。当我尝试访问 /api/products 时,我得到一个 502 bad gateway。
nginx 配置
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/ikse/html;
server_name ikse.fransenit.nl www.ikse.fransenit.nl;
index index.html index.htm;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
# proxy_pass http://localhost:8080;
# 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;
}
location /api/ {
proxy_pass https://localhost:3000;
}
listen [::]:443 ssl; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/ikse.fransenit.nl/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/ikse.fransenit.nl/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
我错过了什么和/或做错了什么?
【问题讨论】:
-
您可以尝试将 localhost 替换为 127.0.0.1 并再试一次,看看是否有效?还将 https 更改为 http(除非您在 nodejs 服务器中有 https)从位置 - /api/ 块。
标签: angular nginx nestjs nginx-config nginx-location