在这种情况下 -
本周我们设置了nginx和HTTPS(通过Let' s加密),这意味着当用户访问www.oursite.com时 - 它被重定向到具有漂亮绿色锁定和安全站点的https站点。到现在为止还挺好。但是,当用户输入她的电子邮件时,app2应该调用app1,并且应该发送带有注册令牌的电子邮件。这在我们尝试设置nginx之前运行良好 - 并在两个应用程序上使用http。现在这个电话没有发生。这是我们的nginx设置:
server {
listen 80;
listen [::]:80;
root /var/www/oursite.com/html;
index index.html index.htm index.nginx-debian.html;
server_name oursite.com www.oursite.com;
location / {
try_files $uri $uri/ =404;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/oursite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/oursite.com/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
if ($scheme != "https") {
return 301 https://$host$request_uri;
} # managed by Certbot
# Redirect non-https traffic to https
# if ($scheme != "https") {
# return 301 https://$host$request_uri;
# } # managed by Certbot
}
我的问题(开发人员#1) - 我应该将我的应用中的所有路由(后端应用 - app1 - 后端)替换为https而不是http吗?来自https网站的Apparently Chrome is not calling http request(就我们而言) 然后我应该如何设置nginx - 我相信我应该在nginx设置中添加另一个位置部分。 如果还有其他建议,请告诉我们。
答案 0 :(得分:0)
每个端口必须获得自己的服务器{}块,因此端口80获取一个,端口443获得另一个端口,每个端口都有一个listen指令到相应的端口...在上面你有两个端口在同一个服务器{}块< / p>
如果应用程序暴露在互联网上,他们应该使用https,如果不是他们使用http的端口80块的传入流量必须被重定向以将流量发送到443 ...所以你的nginx配置文件看起来类似于< / p>
server {
listen 80 ;
listen [::]:80 ;
server_name example.com, www.example.com;
# Redirect all HTTP requests to HTTPS
rewrite ^/(.*) https://example.com/$1 permanent;
}
server {
listen 443 ssl ;
listen [::]:443 ssl ;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/oursite.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/oursite.com/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
location / {
# direct traffic to my server on its host IP and port
proxy_pass http://172.19.0.5:3000/; # notice http not https
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
}
}
在你的情况下看起来app1没有暴露在互联网上,因此没有出现在你的nginx配置中...它只接收来自app2下游的http流量...所有上述配置仅适用于你的app2 ...使用安全https端口443(或端口80被重定向到443)的传入互联网流量接收所谓的TLS终止...通过nginx TLS终止从互联网屏蔽的应用接收http流量而不是https这是好的,因为应用程序端口是无法从互联网上看到...所以你的app2获得http流量而不是https
答案 1 :(得分:0)
我们通过将app1(后端)设置为https来实现此功能。但是,除了firefox之外,这适用于所有主流浏览器。所以我想我现在发一个新问题。该网站没有通过Firefox上的表单 - 但只有在地址没有www。这意味着https://testsite.com - &gt;不工作,https://www.testsite.com工作正常。但是在所有其他浏览器上工作正常。