LNMP配置SSL证书

发布时间:2020/2/27 10:16:46 打印 字号:

一、将nginx文件夹的SSL证书可以上传到目录cert,文件夹可以自己创建:

Gworg证书文件目录

二、进入nginx配置文件目录:/usr/local/nginx/conf/nginx.conf

三、nginx.conf文件添加代码:

#443端口

listen 443;

#强制HTTPS访问代码

if ($server_port = 80) {

rewrite ^(.*)$ https://$host$1 permanent;

}

#SSL证书配置证书目录

ssl on;

ssl_certificate /usr/local/nginx/cert/1_gworg.com_bundle.crt;

ssl_certificate_key /usr/local/nginx/cert/2_gworg.com.key;

nginx.conf代码添加后参考:

server
    {
        listen 80;
	listen 443;
        server_name gworg.com www.gworg.com;
        index index.html index.htm index.php default.html default.htm default.php;
		if ($server_port = 80) {
rewrite ^(.*)$ https://$host$1 permanent;
}
        root  /home/wwwroot/gworg;
        ssl on;
        ssl_certificate /usr/local/nginx/cert/1_gworg.com_bundle.crt;
        ssl_certificate_key /usr/local/nginx/cert/2_gworg.com.key;
		include other.conf;
		#error_page   404   /404.html;
		location ~ [^/]\.php(/|$)
			{
				# comment try_files $uri =404; to enable pathinfo
				try_files $uri =404;
				fastcgi_pass  unix:/tmp/php-cgi.sock;
				fastcgi_index index.php;
				include fastcgi.conf;
				#include pathinfo.conf;
			}

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

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

		access_log  /home/wwwlogs/gworg.com.log  access;
	}

四、配置完毕后,使用SSH登录重启服务器nginx环境命令:/etc/init.d/nginx restart