我有一台Nginx服务器,该服务器在网络内部进行通信以访问数据库,而在外部进行通信以进行用户访问。
我分两个部分创建了一个应用程序。 在Angular中开发的用于显示数据的部件。 (https:// // mydomain /) 在NodeJs中开发的用于访问数据库的部件。 (Pm2:http://127.0.0.1:4000,来自Angular:https:// // mydomain / api2 /路径)
我的nginx服务器包含多个站点。所以我每个站点只有一个conf文件。
我第一次为每个零件创建2个conf文件。但是我被CORS的安全性所阻止。
问题:
这是我的配置文件:
(我只制作了一个conf文件。它针对Angular应用程序,并将proxy_pass用于nodeJs)
server {
listen 80 ;
listen [::]:80 ;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
gzip on;
gzip_comp_level 3;
gzip_types text/plain text/css application/javascript image/*;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com www.example.com;
access_log logs/example.access.log main;
error_log logs/example.error error;
root /var/www/angularapp/;
index index.html index.htm index.nginx-debian.html index.php;
location / {
try_files $uri $uri/ /index.html;
}
location /api2 {
proxy_pass http://127.0.0.1:4000;
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;
}
gzip off;
}
你知道出什么事了吗? 谢谢。