我有一个由angular开发的应用程序作为前端,并为后端开发了弹簧靴。
我将它们部署在Nginx
服务器上运行的Ubuntu
中,其中包括对ssl证书进行加密
前端部署在以下路径/var/www/my-app-domain.local
中
后端是一个运行在端口8080上的jar
Nginx
配置位于/etc/nginx/conf.d/my-app-domain.local.conf
的以下文件中
server {
listen 80;
listen [::]:80;
server_name my-app-domain;
location /api/ {
proxy_pass http://localhost:8080/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
}
server {
server_name my-app-domain www.my-app-domain; # managed by Certbot
index index.html;
root /var/www/my-app-domain.local;
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.html;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/my-app-domain/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/my-app-domain/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
}server {
if ($host = my-app-domain) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = my-app-domain) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
server_name my-app-domain www.my-app-domain;
return 404; # managed by Certbot
}
当我在浏览器中调用域名时,它拒绝了来自Web应用程序的API调用 在控制台中显示此错误:无法加载资源:net :: ERR_CONNECTION_REFUSED ,无法调用http://localhost:8080/api/ *****
但是,当我从浏览器调用相同的API时,它调用成功,没有任何问题。
我的Ngnix配置不正确吗?我应该如何处理此错误?在生产环境中调用API的正确方法是什么?