我在服务器上通过ssl运行我的nginx反向代理,域名为:mydomain.com
。这在nginx配置下面:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream myApp {
server my-app:8080;
}
server {
listen 80;
server_name mydomain.com;
root /usr/share/nginx/html;
return 301 https://$host$request_uri;
}
server{
listen 443 ssl;
root /usr/share/nginx/html;
server_name mydomain.com;
include /etc/nginx/mime.types;
ssl_protocols TLSv1.2 TLSv1.3 TLSv1.1;
ssl_certificate /etc/nginx/certs/myapp_chain.pem;
ssl_certificate_key /etc/nginx/certs/private.pem;
proxy_set_header X-Forwarded-For $proxy_protocol_addr; # To forward the original client's IP address
proxy_set_header X-Forwarded-Proto $scheme; # to forward the original protocol (HTTP or HTTPS)
proxy_set_header Host $host; # to forward the original host requested by the client
proxy_buffers 4 256k;
proxy_buffer_size 128k;
proxy_busy_buffers_size 256k;
location / {
index index.html;
try_files $uri $uri/ /index.html;
}
location /portal {
proxy_pass http://myApp/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
}
当我在本地工作时,应用程序运行良好。当我用不同的端口(但不是在nginx后面)运行它时,它可以很好地访问。
问题是当我用mydomain.com/portal
访问它时,我得到了这个错误(如图所示)。我允许CORSBTW。
浏览器中的控制台显示:
1条答案
按热度按时间c9x0cxw01#
我想明白了有两个地方我们应该进行更改以考虑/portal子路径。
在Angular项目中的index.html(JHipster中的webapps)
在nginx配置文件中,我们应该添加这一行:
在将请求转发到myApp服务之前,从请求URI中删除
"/portal"
前缀。