目前,我正在使用一個AWS Ubuntu EC2實例,在端口3000上運行一個具有Nginx反向代理的Node.js應用程序。我一直在嘗試啓用HTTPS並添加SSL證書,並且我已經成功,因爲我在nginx.conf文件中沒有發現任何錯誤。但是,我正在將我的主網站「example.com」重定向到AWS服務器的公共DNS,並且當我嘗試加載「http://example.com」或「https://example.com」頁面時,我從Firefox中收到「無法連接」錯誤,這是我的測試瀏覽器。當我運行sudo nginx -t
時,配置文件中沒有語法錯誤,當我檢查/var/log/nginx/error.log
文件時,它是空的。以下是我目前的nginx.conf文件。Nginx在轉發到其他URL時啓用HTTPS/SSL
更新:我改變服務器名稱從example.com
到我的服務器的公共DNS,讓我們把它叫做amazonaws.com
。現在,當我輸入https://amazonaws.com
時,通過ssllabs.com運行網站時會出現頁面加載和SSL證書顯示。但是,當我輸入amazonaws.com
或http://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;
}
}
}