gpt4 book ai didi

ssl - Nginx 转发到其他 URL 时启用 HTTPS/SSL

转载 作者:太空宇宙 更新时间:2023-11-03 13:54:08 24 4
gpt4 key购买 nike

目前,我正在使用一个 AWS Ubuntu EC2 实例,在端口 3000 上运行一个 Node.js 应用程序,它有一个 Nginx 反向代理。我一直在尝试启用 HTTPS 并添加 SSL 证书,并且我已经成功了,因为我在 nginx.conf 文件中没有收到任何错误。但是,我将我的主要网站“example.com”重定向到 AWS 服务器的公共(public) DNS,当我尝试加载“http://example.com”或“https://example.com”页面时,我收到“无法连接”来自 Firefox 的错误,这是我的测试浏览器。此外,当我运行 sudo nginx -t 时,配置文件中没有语法错误,当我检查 /var/log/nginx/error.log 文件时,它是空的。下面是我当前的 nginx.conf 文件。

更新:我将 server_name 从 example.com 更改为我服务器的公共(public) DNS,我们称它为 amazonaws.com。现在,当我输入 https://amazonaws.com 时,页面加载并且 SSL 证书在通过 ssllabs.com 运行网站时显示。但是,当我输入 amazonaws.comhttp://amazonaws.com 时,我会像以前一样得到一个空白页面。

user root;
worker_processes 1;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
# max_clients = worker_processes * worker_connections / 4
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;

gzip on;
gzip_comp_level 6;
gzip_vary on;
gzip_min_length 1000;
gzip_proxied any;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_buffers 16 8k;

# backend applications
upstream nodes {
server 127.0.0.1:3000;
keepalive 64;
}

server {
listen 80;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/example_com.crt;
ssl_certificate_key /etc/nginx/ssl/example_com.key;
ssl_protocols SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
server_name example.com;

# everything else goes to backend node apps
location / {
proxy_pass http://nodes;

proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Connection "";
proxy_http_version 1.1;
}
}
}

最佳答案

你应该给这个服务器定义

server {
listen 80;
return 301 https://$host$request_uri;
}

还有一个服务器名称(例如 amazonaws.com)。

关于ssl - Nginx 转发到其他 URL 时启用 HTTPS/SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27107527/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com