Nginx配置https访问

Nginx配置文件模板

  • nginx配置支持https 80端口访问自动跳转443
  • 配置禁止脚本文件访问指定目录
  • 配置目录自动按日期分割
server{
    ##配置80端口自动跳转443
    listen 80;
    server_name server_name 52qcg.cn www.52qcg.cn; 
    rewrite ^(.*)$ https://$host$1 permanent;
    location / {
    index index.shtml index.htm index.php index.html;
    }
}

server {
        listen 443;
        #listen [::]:80 default_server ipv6only=on;
        server_name 52qcg.cn www.52qcg.cn;
        index index.shtml index.htm index.php index.html;
        root  /data/www/cmmblog/public;
        
        ssl on;
        ssl_certificate cert/3086423_52qcg.cn.pem;   #将domain name.pem替换成您证书的文件名。
        ssl_certificate_key cert/3086423_52qcg.cn.key;   #将domain name.key替换成您证书的密钥文件名。
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        #error_page   404   /404.html;
        # Deny access to PHP files in specific directory
        location ~ /(wp-content|upload|wp-includes|images)/.*\.php$ { deny all; }
	#location ~ /(static/admin/fonts|static/admin/images|static/admin/style|wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }	

        include enable-php.conf;
        location / {
        if (!-e $request_filename) {
        rewrite ^(.*)$ /index.php?s=/$1 last;
        break;
        }
        }

        location /nginx_status
        {
            stub_status on;
            access_log   off;
        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }
        ##配置按日期生成目录
	if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})")
	{
    	set $year $1;
    	set $month $2;
    	set $day $3;
    	set $hour $4;
    	set $minutes $5;
    	set $seconds $6;
	}	
        access_log  /home/wwwlogs/cmmblog/cmmblog_access_$year$month$day.log;
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值