免费注册 查看新帖 |

Chinaunix

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

[服务应用] Nginx做反向代理转发http和https的请求在location配置时差别巨大? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-05-04 16:52 |只看该作者 |倒序浏览
谁能解释一下?
default.conf中上面的80端口的http前端转发时昨天测好的,没问题;今天这个https转发是刚刚测好的,也没问题,

但是2者的区别,location在http转发时必须带/,而http啥的必须不带/,否则地址不对报错。
location  /site1/ {
                        proxy_pass http://192.168.137.12;
                }


                location  /site2/ {
                        proxy_pass http://192.168.137.13;
                }

以下是https带着/和不带/的错误和正确的日志。
192.168.137.11 - - [04/May/2013:16:40:01 +0800] "GET /page1.html HTTP/1.0" 404 168 "-" "Opera/9.80 (Windows NT 6.1; Edition Next) Presto/2.12.388 Version/12.12"
192.168.137.11 - - [04/May/2013:16:40:43 +0800] "GET /site2/page1.html HTTP/1.0" 200 30 "-" "Opera/9.80 (Windows NT 6.1; Edition Next) Presto/2.12.388 Version/12.12"


default.conf的配置文件如下

[root@nginx1 conf.d]# more default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        #root   /usr/share/nginx/html;
        root    /home/root/web;
        index  index.html index.htm;

location  /site1/ {
proxy_pass http://192.168.137.12/site1/;
}


location  /site2/ {
proxy_pass http://192.168.137.13/site2/;
}




    }

    #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   /usr/share/nginx/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;
    #}
}



server {  
        ### server port and name ###  
        listen          443 ssl;  
        server_name     main443;  
        ssl on;  
   
        ### SSL log files ###  
        access_log      /var/log/nginx/ssl-access.log;  
        error_log       /var/log/nginx/ssl-error.log;  
   
        ### SSL cert files ###  
        ssl_certificate      ssl/main.crt;  
        ssl_certificate_key  ssl/main.key;  
        ### Add SSL specific settings here ###  
        keepalive_timeout    60;  
   
        ###  Limiting Ciphers ########################  
        # Uncomment as per your setup  
        #ssl_ciphers HIGH:!ADH;  
        #ssl_perfer_server_ciphers on;  
        #ssl_protocols SSLv3;  
        ##############################################  
        ### We want full access to SSL via backend ###  
        location / {  
                ### force timeouts if one of backend is died ##  
                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-Forwarded-For $proxy_add_x_forwarded_for;  
   
                ### Most PHP, Python, Rails, Java App can use this header ###  
                proxy_set_header X-Forwarded-Proto http;  
   
                ### By default we don't want to redirect it ####  
                #proxy_redirect     off;  

                location  /site1/ {
                        proxy_pass http://192.168.137.12;
                }


                location  /site2/ {
                        proxy_pass http://192.168.137.13;
                }

      }

}
[root@nginx1 conf.d]#   

论坛徽章:
0
2 [报告]
发表于 2013-05-09 22:53 |只看该作者
???????????????/

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-10-02 06:20:00IT运维版块每月发帖之星
日期:2015-09-11 19:30:52IT运维版块每周发帖之星
日期:2015-09-11 19:20:31IT运维版块每日发帖之星
日期:2015-08-26 06:20:00每日论坛发贴之星
日期:2015-08-20 06:20:00IT运维版块每日发帖之星
日期:2015-08-20 06:20:002015年辞旧岁徽章
日期:2015-03-03 16:54:15金牛座
日期:2014-05-04 16:58:09双子座
日期:2013-12-17 16:44:37辰龙
日期:2013-11-22 15:20:59狮子座
日期:2013-11-18 22:55:08射手座
日期:2013-11-12 10:54:26
3 [报告]
发表于 2013-05-10 08:43 |只看该作者
location差别不大,只需要在server 那里加listen 80 和443即可。

看到你的写的那么多,真看不下去。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP