0
我在努力與NGINX並設置我的v主機。我試圖設置一個虛擬主機重定向HTTP請求到HTTPS,然後到我的應用程序(當它是443)NGINX SSL過於頻繁地重定向
我的操作系統是Ubuntu 16.04,我使用的是NGINX 1.10.3。
的nginx.conf看起來像(其主要是默認):
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_tokens off;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
我ServerBlocks /虛擬主機看起來像:
server {
listen 443 ssl;
server_name xxx.com;
# Prevent MITM
add_header Strict-Transport-Security "max-age=31536000";
ssl_certificate "/etc/nginx/ssl/xxx.com.pem";
ssl_certificate_key "/etc/nginx/ssl/xxx.com.key";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location/{
proxy_pass http://localhost:2237;
}
}
server {
listen 80;
server_name xxx.com;
return 301 https://$server_name$request_uri;
}
現在的問題是,要麼如果我使用HTTP或HTTPS,它會嘗試將我重定向到HTTPS,因此我陷入了無限循環的重定向。
我完全不知道我的錯誤在哪裏。
每個VHost都在一個文件中。端口2237上的應用程序是nodeJS Express Server。我也使用CloudFlare的(我從他們身上我的SSL證書)
編輯:
從curl -I
輸出是:
$ curl -I https://example.com
HTTP/1.1 301 Moved Permanently
Date: Fri, 06 Oct 2017 19:42:19 GMT
Content-Type: text/html
Connection: keep-alive
Set-Cookie: __cfduid=d827df762e20a4e321b92b34bd15546621507318939; expires=Sat, 06-Oct-18 19:42:19 GMT; path=/; domain=.example.com; HttpOnly
Location: https://example.com/
Server: cloudflare-nginx
CF-RAY: 3a9b1a6a4e4564d5-FRA
運行'nginx -T'並驗證沒有額外的配置正在加載 –
@TarunLalwani不,它只是配置 – dunklesToast
嘗試在'proxy_pass'塊中添加'proxy_redirect http:// localhost:2237/https:// $ host /;'。我認爲你的nodejs應用程序正在做一個重定向,這可能導致這些重定向 –