https在nginx在的配置

举一个例子nginx的https,对nginx了解还是太少,将证书和秘钥文件放在config的目录下,名字server.pem和server.key,

1.针对webservice访问无法使用https的处理,对webservice不走https(肯定有完美解决方法,不过我没有发现)

对于所有的/hnny/的7000端口请求均会使用https协议,

对于所有的/hnny/的7002端口请求会跳转到https://localhost:7000/,然后使用https协议

对于所有的/hnny/webservice/的7002端口请求跳转到http://localhost:9080,然后使用http协议(之所以不用https协议,是因为rewrite和return均会重定向,将导致webservice服务无法正常使用)

#user  nobody;
worker_processes  1;

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

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

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;

    # 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 {
        #监听7000端口,限定为只能使用https访问
        listen       7000 ssl;
        server_name  localhost;

        ssl_certificate      server.pem;
        ssl_certificate_key  server.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        client_max_body_size; #访问时body的最大容量

    location /hnny/ {
            proxy_pass  http://localhost:9080;
        }

    #携带参数,将http转换为https(一般建议用这种,携带了请求的参数),重定向
       error_page 497  https://$http_host$request_uri;
       #不携带参数,将http转换为https
    #error_page 497 https://$http_host$uri;
    }
    server {
        listen 7002;
        server_name localhost;
        #当是webservice请求,不再使用https,直接访问真正的服务器
        location /hnny/webservice/ {
        proxy_pass  http://localhost:9080;
        }
         #将请求转成https
        location /hnny/ {
        rewrite  ^(.*)$ https://localhost:7000$1;
        }
    }
}

        注:497 - normal request was sent to HTTPS

        此虚拟站点只允许https访问时,当用http访问时nginx会报出497错误码

 2.在谷歌浏览器中,进行https访问时,页面中所有的http请求会自动转换为https请求。

3.应用中页面有绝对地址访问的,可能出现下面问题:

1)就是img、js、css或者其他静态资源使用绝对地址访问(真正服务器的地址:端口)就可能会找不到资源,例如nginx代理后访问的可能是内网地址,这样外网你就无法访问

2)若果浏览器没有进行http到https的安全转换,可能又会出现跨域的问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值