Nginx keeps redirecting to HTTPS for no apparent reason?

时间:2016-04-25 09:28:37

标签: ruby-on-rails nginx passenger

I've set up an Ubuntu VPS and everything is up and running but I keep getting redirected to HTTPS which I don't want.

This is my config:

/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;
        }
}

This is my output for 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"

Does anyone know why I keep getting redirected?

1 个答案:

答案 0 :(得分:1)

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

config.force_ssl = false