首页 > Web开发 > 详细

Nginx配置SSL实现HTTPS访问

时间:2019-05-29 18:56:12      阅读:108      评论:0      收藏:0      [点我收藏+]

nginx配置文件如下:

 server {
        listen       443 ssl;
        server_name  www.domain.com;
        root /www/web;
        index index.html index.php;

        ssl_certificate      cert/2268832_www.domain.com.pem;
        ssl_certificate_key  cert/2268832_www.domain.com.key;

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

        ssl_ciphers  ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_prefer_server_ciphers  on;

        location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
                expires max;
                log_not_found off;
        }

       if ( $host != ‘www.domain.com‘ ) {
          rewrite "^/(.*)$" https://www.domain.com/$1 permanent;
        }


        location / {
                # Check if a file or directory index file exists, else route it to index.php.
                try_files $uri $uri/ /index.php;
        }

        location ~* \.php$ {
                fastcgi_pass 127.0.0.1:9000;
                include fastcgi.conf;
        }

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


       server {
        listen 80;
        server_name www.domain.com; 
        rewrite ^(.*)$ https://$host$1 permanent;

       }

检测配置是否正确命令:

/usr/local/nginx/nginx -t

配置正确重启nginx:

/usr/local/nginx/nginx -s reload

最后就可以访问网站看到https了。

Nginx配置SSL实现HTTPS访问

原文:https://www.cnblogs.com/phperlinxinlan/p/10945361.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!