nginx构建https

时间:2023-02-13 19:55:25

1、生成证书
#openssl genrsa -des3 -out server.key 1024
#openssl req -new -key server.key -out server.csr
#openssl rsa -in server.key -out server_nopwd.key
#openssl x509 -req -days 365 -in server.csr -signkey server_nopwd.key -out server.crt

2、配置Nginx

server {
    listen 443;
    ssl on;
    ssl_certificate  /usr/local/nginx/conf/server.crt;
    ssl_certificate_key  /usr/local/nginx/conf/server_nopwd.key;
}

3、重启Nginx,必须stop再start

使用rewrite方式 ,强制使用https

p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #000000; background-color: #ffffff }
span.s1 { }

server {

listen 80;

server_name schedule.localhost;

return 301 https://$server_name$request_uri;

}

更详细的请自己百度,做个笔记而已