Nginx保持重定向到HTTPS没有明显的原因?

问题描述:

我已经建立了一个Ubuntu VPS,并且一切都正常并且正在运行,但我不断收到重定向到HTTPS,我不想要。Nginx保持重定向到HTTPS没有明显的原因?

这是我的配置:

/etc/nginx/nginx.conf

user www-data; 
worker_processes 4; 
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; 

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE 
    ssl_prefer_server_ciphers on; 

    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/error.log; 

    gzip on; 
    gzip_disable "msie6"; 

    passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini; 
    passenger_ruby /home/deploy/.rvm/wrappers/ruby-2.3.0/ruby; 

    include /etc/nginx/conf.d/*.conf; 
    include /etc/nginx/sites-enabled/*; 
} 

/etc/nginx/sites-available/default

server { 
     listen 80 default_server; 

     server_name www.example.com localhost; 
     passenger_enabled on; 
     rails_env staging; 
     root   /home/deploy/example.com/current/public; 

     error_page 500 502 503 504 /50x.html; 
     location = /50x.html { 
      root html; 
     } 
} 

这是我lynx example.com输出:

Looking up example.com first 
Looking up example.com 
Making HTTP connection to example.com 
Sending HTTP request. 
HTTP request sent; waiting for response. 
HTTP/1.1 301 Moved Permanently 
Data transfer complete 
HTTP/1.1 301 Moved Permanently 
Using https://example.com/ 
Looking up example.com 
Making HTTPS connection to example.com 
Alert!: Unable to connect to remote host. 

lynx: Can't access startfile http://example.com/ 

/var/log/nginx/access.log

x.x.x.x - - [25/Apr/2016:09:25:30 +0000] "GET/HTTP/1.0" 301 0 "-" "Lynx/2.8.8rel.2 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/1.0.2g" 

有谁知道为什么我一直被重定向?

+1

我认为在Rails中有一个选项可以强制https,也许这是导致重定向的原因。 nginx配置在这里似乎不是罪魁祸首,除非应用了其他配置文件。 – Slicedpan

+0

谢谢!就是这样:'config.force_ssl = false'。如果你把它写成答案,我会投票。 – Cojones

在rails中有一个配置选项来强制使用SSL。尝试设置

config.force_ssl = false