310-Nginx服务器支持https配置(七牛ssl证书)

2017-11-26  本文已影响124人  霄峰

Nginx服务器支持https配置(七牛ssl证书)


1. 第一步:去七牛官网申请ssl证书


2. 第二步:使用ssl证书来支持Nginx服务器https

前提:将下载的ssl证书上传到服务器的/var/cert/目录下(没有目录自行创建)

# SSL配置
server {
        listen 443;

        # 这里是你的www目录
        root /var/www/demo-video;

        # 这里添加index.php
        index index.php index.html index.htm;

        # 这里是你的域名
        server_name demo-video.yunfeng365.com;

        ssl on;
        ssl_certificate /var/cert/demo-video.yunfeng365.com.crt;
        # ssl_dhparam /var/cert/demo-video.yunfeng365.pem;
        ssl_certificate_key /var/cert/demo-video.yunfeng365.com.key;

        ssl_session_timeout 5m;

        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
        ssl_prefer_server_ciphers on;


        location / {
                # 支持index.php隐藏
                try_files $uri $uri/ /index.php?$query_string;
        }

        # 支持PHP
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass 127.0.0.1:9000;
        }
}

# 当访问`http://demo-video.yunfeng365.com`时,跳转到`https://demo-video.yunfeng365.com`
server {
        listen 80;

        # Make site accessible from http://localhost/
        server_name demo-video.yunfeng365.com;
        return 301 https://demo-video.yunfeng365.com$request_uri;
}


上一篇 下一篇

猜你喜欢

热点阅读