我的 quasar(VueJs 应用程序)和 nodejs(作为 API)应用程序有以下 nginxconf
正如您所看到的,我的 Nodejs 应用程序位于 /api 位置,其余配置适用于我的 Quasar (vuejs) 应用程序...
我遇到的问题如下。如果我仅配置 http(注释掉 ssl 行并设置为侦听 80),那么我的应用程序运行正常。如果我使用 certbot 并启用 HTTPS,则会收到页面错误太多重定向。
server {
server_name stage.moj-racun.si www.stage.moj-racun.si;
access_log /var/log/nginx/my-bills-access.log;
error_log /var/log/nginx/my-bills-error.log error;
root /home/ubuntu/myBills/frontend/dist/spa/stage;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html;
charset utf-8;
location / {
try_files $uri $uri/ /index.html;
}
location = /favicon.ico { access_log off; log_not_found off; }
location ~ /\.(?!well-known).* {
deny all;
}
location /api {
root /home/ubuntu/myBills/backend;
proxy_set_header X-Forwarded-Proto $scheme; # Add this line to preserve the protocol
proxy_pass http://localhost:3000;
proxy_connect_timeout 60s;
proxy_read_timeout 5400s;
proxy_send_timeout 5400s;
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 = /robots.txt {
default_type text/plain;
return 200 "User-agent: *\nDisallow: /\n";
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/stage.moj-racun.si/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/stage.moj-racun.si/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 {
listen 80;
server_name stage.moj-racun.si www.stage.moj-racun.si;
location / {
return 301 https://$host$request_uri;
}
}
不管我是否在我的服务器上发出https://stage.moj-racun.si/api/country或http://stage.moj-racun.si/api/country请求,我总是会收到相同的错误。我的 nginx.conf 是默认的(我没有做任何更改)。我写这篇文章是因为我只在 access.log 中看到服务器上的请求,这意味着 my-bills-access.log 和 my-bills-error.log 是空的......
我缺少什么?也许是问题所在,因为我使用子域?
如果您需要任何其他信息,请告诉我,我将提供...
Cloudflare 是“问题”,因为它可能期望您的网络服务器在 http 上运行,而不是 https。有几个选项可以解决该问题(您通过完全加密解决了它):
1. 加密关闭:
cloudflare 代理和您的网络服务器/代理都使用 http。
2、灵活:
Cloudflare 负责 https 和加密,您的服务器仅接受 http。客户端和网站之间的流量已加密,但 cloudflare 和您的网络服务器之间的流量未加密。
您可以通过仅侦听端口 80 (http) 来使其与当前配置配合使用,而不使用任何证书。删除第二个重定向指令。
3. 完整:
所有流量都经过加密,甚至是 cloudflare 和您的网络服务器之间的流量。
4. 完全(严格):
与 #3 相同,但网络服务器上的证书必须可信。
这是一个 cloudflare 问题!尽管这是一个问题:)您需要将 SSL/TLS 加密模式设置为Full