環境是使用lnmp一鍵安裝包搭建的;
1 首先去這個網站下載證書:免費ssl證書
最終會獲得兩個文件
2:在/usr/local/nginx/conf建立cert目錄把這兩個文件放進去,這個地址後面有用。
編輯/usr.local/nginx/conf/nginx.conf:添加下面這段:php
server { listen 443; server_name www.domain.cn; #這裏改爲你的 ssl on; root /home/wwwroot/default; #你的地址 #下面兩個是上面下載的兩個文件地址 ssl_certificate /usr/local/nginx/conf/cert/full_chain.pem; ssl_certificate_key /usr/local/nginx/conf/cert/private.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; index index.php index.html index.htm; # 優先解析php文件 # 匹配後綴爲php的文件 location ~ \.php?.*$ { root /home/wwwroot/default; # 設置網站根目錄 fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include fastcgi_params; } location /nginx_status { stub_status on; access_log off; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /\. { deny all; } access_log /home/wwwlogs/access.log; }
注意最終格式是http:{server{}}不要把這段寫在http外面了
若是有機率出現:No input file specified.可是重啓php後正常
vim fastcgi.conf
將下面這行,註釋
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
而後,重啓lnmpcss
轉自html
lnmp給網站增長https - 蘇賀賀的我的博客 - CSDN博客 https://blog.csdn.net/qq_41179401/article/details/86104881nginx
php 將http轉化爲https 小程序部署上線 - 媛媛*小怪獸 - 博客園 https://www.cnblogs.com/dennyxiao/p/9009905.html小程序