免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 18776 | 回复: 6
打印 上一主题 下一主题

Nginx反向代理https求助 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-05-15 14:37 |只看该作者 |倒序浏览
想请教一下论坛里的高手

如何配置nginx去反向代理远端的https下的web服务器。下面是我的配置文件nginx.conf的内容,请大家指正

#cat nginx.conf

user  nginx nginx;
worker_processes  2;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    worker_connections  4096;
#    use kqueue;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] $request '
    #                  '"$status" $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  0;
    #keepalive_timeout  65;


    gzip  on;
    gzip_min_length 1100;
    gzip_buffers 4 8k;
    gzip_types text/plain;

    output_buffers 1 32k;
    postpone_output 1460;

    tcp_nodelay on;
    #send_lowat 12000;

    keepalive_timeout 75 20;

upstream xp.test.com {
server 192.168.6.8:80;
}

    server {
        listen       80;
        server_name  192.168.44.151;
        root html;
        #charset koi8-r;
        charset utf-8;
        access_log  logs/host.access.log;

        #location / {
        #    root   html;
        #    index  index.html index.htm index.php;
        #}

       location / {
       proxy_pass http://xp.test.com;
       proxy_set_header X-Real-IP $remote_addr;
       }

       if (-d $request_filename){
       rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
       }

       location /nginx_status {
       stub_status on;
       access_log off;
       }

include enable_php;

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    server {
        listen       443;
       server_name  localhost;

        ssl                  on;
        ssl_certificate      /usr/local/nginx/conf/server.crt;
        ssl_certificate_key  /usr/local/nginx/conf/server.key;
        error_page 497 "https://$host$uri?$args";
        ssl_session_timeout  5m;

        ssl_protocols  SSLv2 SSLv3 TLSv1;
        ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
        ssl_prefer_server_ciphers   on;

        location / {
    #        root   html;
    #        index  index.html index.htm;
        include proxy.conf;
        auth_basic "status";
        }
    }

}

对上面的配置文件做一些基本的解释:我的nginx代理服务器ip地址为192.168.44.151,真实的服务器为192.168.6.8.现在的问题是,我的思路为用户请求到达nginx代理服务器的80端口后,代理将请求转发至远端web服务器的80端口(因为首页未加密,但首页上有进入被加密内容的链接),当用户在点击首页上被加密内容链接后便进入加密页面,即https。

以上的配置能够正常看到非加密内容,但是一旦点击含有加密内容的链接后,便会报错。内容为“无法显示该页面”,远端服务器的证书和私钥文件均已上传至这台nginx上

想问一下,上面的配置中是哪里配置的有问题呢?

附:
#cat proxy.conf
#proxy_set_header X-Forwarded-For $remote_addr;
#proxy_set_header REMOTE_ADDR $remote_addr;
#proxy_set_header RealIP $remote_addr;
proxy_set_header Host $proxy_host;
#proxy_set_header Accept-Encoding '';

#proxy_hide_header X-Cache;
#proxy_hide_header X-Powered-By;
#proxy_hide_header Last-Modified;
#proxy_hide_header Date;
#proxy_hide_header Content-Length;
#proxy_hide_header Content-Language;
#proxy_hide_header Cache-Control;

#proxy_pass_header Server;

client_max_body_size    8m;
proxy_connect_timeout   15s;
proxy_send_timeout      1m;
proxy_read_timeout      1m;
proxy_temp_file_write_size 1024m;
proxy_buffer_size         32k;
proxy_buffers             4 32k;
proxy_busy_buffers_size 64k;

proxy_ignore_client_abort on;

proxy_next_upstream error timeout invalid_header http_503;

论坛徽章:
0
2 [报告]
发表于 2009-05-15 15:59 |只看该作者
加密? 443端口的那个?

论坛徽章:
0
3 [报告]
发表于 2009-05-15 16:11 |只看该作者
首先感谢回帖

我现在的情况是,我的151上的nginx可以反向代理真实服务器首页上非加密的内容,且浏览这些内容都是正常的。同时浏览首页也是正常的

但首页上有一些连接,点击之后便会被https加密,所以当点击这些链接之后,便会出现 无法显示该页面 的报错内容

不知道该如何去解决这些问题

感谢每一位回帖的兄弟

论坛徽章:
0
4 [报告]
发表于 2009-05-15 19:04 |只看该作者
楼主,你看看我这个是否能帮到您.不是广告.
http://my.benorz.org/index.php/more/62
我之前也做nginx ssl的.因为公司的业务系统买了一个ssl.后端的服务器要做集群.所以才要这么做.呵呵

论坛徽章:
0
5 [报告]
发表于 2009-05-16 17:02 |只看该作者

回复 #1 ProfessorTian 的帖子

需要一个保持时间的

论坛徽章:
0
6 [报告]
发表于 2009-05-18 12:51 |只看该作者
想问一下

nginx代理的443端口和被代理的web服务器的443端口之间是个什么关系

当nginx代理远程web的443端口时,这个过程是什么样的

请高手指点

论坛徽章:
0
7 [报告]
发表于 2013-06-25 16:31 |只看该作者
本帖最后由 心若寒江雪 于 2013-06-25 16:32 编辑

请问一下你这个弄出来了吗?
如果弄出来了帮我看看吧
http://bbs.chinaunix.net/thread-4087536-1-1.html
多谢了
回复 1# ProfessorTian


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP