【问题标题】:nginx - Disable http to https redirect?nginx - 禁用 http 到 https 重定向?
【发布时间】:2015-07-16 08:32:51
【问题描述】:

我按照本教程http://www.schenkels.nl/2014/12/reverse-proxy-with-odoo-8-nginx-ubuntu-14-04-lts/ 如何使用 nginx 为 odoo 制作反向代理。

这里一切顺利。但问题出在证书上。 每个浏览器都发誓我的自签名证书不受信任。这是测试服务器,所以我现在并不关心安全性。我尝试使用证书和 ssl 禁用/评论所有内容。但是nginx仍然重定向到https,然后当它没有找到证书时,它只会给出这个错误:

Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have

但是我怎样才能忽略https,而使用http而不进行任何加密呢?我需要在 nginx 内部进行一些调整吗?

例如使用apache,如果没有指定使用安全连接,那么它只是使用普通的http,就是这样。希望其他人对 nginx 有更好的体验。

我调整的配置看起来像这样(我只是评论了一些部分并将rewrite更改为http而不是https):

upstream odoo8 {
server 127.0.0.1:8069 weight=1 fail_timeout=0;
}

upstream odoo8-im {
server 127.0.0.1:8072 weight=1 fail_timeout=0;
}

## http redirects to https ##
server {
listen 80;
server_name _;

# Strict Transport Security
add_header Strict-Transport-Security max-age=2592000;
rewrite ^/.*$ http://$host$request_uri? permanent;
}

server {
# server port and name
listen 443;
server_name _;

# Specifies the maximum accepted body size of a client request,
# as indicated by the request header Content-Length.
client_max_body_size 200m;

# add ssl specific settings
#keepalive_timeout 60;
ssl off;
#ssl_certificate /etc/ssl/nginx/server.crt;
#ssl_certificate_key /etc/ssl/nginx/server.key;

# limit ciphers
#ssl_ciphers HIGH:!ADH:!MD5;
#ssl_protocols SSLv3 TLSv1;
#ssl_prefer_server_ciphers on;

# increase proxy buffer to handle some OpenERP web requests
proxy_buffers 16 64k;
proxy_buffer_size 128k;

#general proxy settings
# force timeouts if the backend dies
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;

# set headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;

# Let the OpenERP web service know that we’re using HTTPS, otherwise
# it will generate URL using http:// and not https://
#proxy_set_header X-Forwarded-Proto https;

# by default, do not forward anything
proxy_redirect off;
proxy_buffering off;

location / {
proxy_pass http://odoo8;
}

location /longpolling {
proxy_pass http://odoo8-im;
}

# cache some static data in memory for 60mins.
# under heavy load this should relieve stress on the OpenERP web interface a bit.
location /web/static/ {
proxy_cache_valid 200 60m;
proxy_buffering on;
expires 864000;
proxy_pass http://odoo8;
}
}

【问题讨论】:

    标签: ssl nginx


    【解决方案1】:

    你只需要注释掉 80 端口上的重定向并监听 80 端口。 这可以通过配置中的以下更新来完成

    upstream odoo8 {
    server 127.0.0.1:8069 weight=1 fail_timeout=0;
    }
    
    upstream odoo8-im {
    server 127.0.0.1:8072 weight=1 fail_timeout=0;
    }
    
    ## http redirects to https ##
    #server {
    #listen 80;
    #server_name _;
    
    # Strict Transport Security
    #add_header Strict-Transport-Security max-age=2592000;
    #rewrite ^/.*$ http://$host$request_uri? permanent;
    #}
    
    server {
    # server port and name
    # listen 443;  # comment out this line
    listen 80;
    server_name _;
    
    # Specifies the maximum accepted body size of a client request,
    # as indicated by the request header Content-Length.
    client_max_body_size 200m;
    
    # add ssl specific settings
    #keepalive_timeout 60;
    ssl off;
    #ssl_certificate /etc/ssl/nginx/server.crt;
    #ssl_certificate_key /etc/ssl/nginx/server.key;
    
    # limit ciphers
    #ssl_ciphers HIGH:!ADH:!MD5;
    #ssl_protocols SSLv3 TLSv1;
    #ssl_prefer_server_ciphers on;
    
    # increase proxy buffer to handle some OpenERP web requests
    proxy_buffers 16 64k;
    proxy_buffer_size 128k;
    
    #general proxy settings
    # force timeouts if the backend dies
    proxy_connect_timeout 600s;
    proxy_send_timeout 600s;
    proxy_read_timeout 600s;
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
    
    # set headers
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
    
    # Let the OpenERP web service know that we’re using HTTPS, otherwise
    # it will generate URL using http:// and not https://
    #proxy_set_header X-Forwarded-Proto https;
    
    # by default, do not forward anything
    proxy_redirect off;
    proxy_buffering off;
    
    location / {
    proxy_pass http://odoo8;
    }
    
    location /longpolling {
    proxy_pass http://odoo8-im;
    }
    
    # cache some static data in memory for 60mins.
    # under heavy load this should relieve stress on the OpenERP web interface a bit.
    location /web/static/ {
    proxy_cache_valid 200 60m;
    proxy_buffering on;
    

    【讨论】:

    • 谢谢。这成功了。但是也有浏览器缓存问题。当我这样改变它时,它仍然在尝试https,但是进入隐私浏览,打开页面没有https
    • 可以使用superuser.com/a/881431/857724在每个站点上禁用导致https重定向的浏览器缓存
    猜你喜欢
    • 1970-01-01
    • 2011-03-29
    • 2018-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-11
    相关资源
    最近更新 更多