nginx配置https

本文介绍了Nginx配置HTTPS的详细步骤。首先需要准备SSL证书文件(.crt)和私钥文件(.key),然后通过配置server块,将HTTP请求重定向到HTTPS(端口443),并设置SSL证书、协议、加密套件等参数。同时提供了支持PHP的配置示例,并建议将配置拆分后使用include导入。

作者:zhuge···预计阅读 24 分钟·688 阅读·0 评论
nginx配置https

先去申请https,并将.crt 和 .key文件准备好

server {
    listen 80;
    server_name i.vxlife.com;
    #将请求转成https
    rewrite ^(.*)$ https://$host$1 permanent;
}

server {         #SSL 访问端口号为 443         listen 443 ssl;          #填写绑定证书的域名         server_name i.vxlife.com;          #证书文件名称         ssl_certificate /usr//i.vxlife.com_bundle.crt;          #私钥文件名称         ssl_certificate_key /usr//i.vxlife.com.key;          ssl_session_timeout 5m;         #请按照以下协议配置         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;          #请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;          ssl_prefer_server_ciphers on;         location / {                 root   html;                 index  index.html index.htm;         }       }


如果要配置php,如下:

server {
        listen       443;
        server_name  i.vxlife.com;

        #证书文件名称         ssl_certificate /usr//i.vxlife.com_bundle.crt;          #私钥文件名称         ssl_certificate_key /usr//i.vxlife.com.key;          ssl_session_timeout 5m;         #请按照以下协议配置         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;          #请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;          ssl_prefer_server_ciphers on;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {             # 这边的路劲填写项目路劲             root   /usr/**/i.vxlife.com/web;             # 记得加上 index.php             index  index.php index.html index.htm;

            if (!-e $request_filename) {                 rewrite . /index.php last;             }         }

        #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;         }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000         #         location ~ .php$ {             # 这边的路劲填写项目路劲             root           /usr/**/i.vxlife.com/web;             fastcgi_pass   127.0.0.1:9000;             fastcgi_index  index.php;             # 要修改为$document_root             fastcgi_param  SCRIPT_FILENAME  $document_root$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;         #}     }


也可以单独写到一些文件中,然后

http {
    include       mime.types;
    ##导入这些conf文件
    include       ../modules/*.conf;
    default_type  application/octet-stream;


相关文章

评论

加载中...