使用nginx部署靜態(tài)網(wǎng)站和ssl證書(shū)
原料:服務(wù)器*1? ssl證書(shū)*1? 域名*1? ?藍(lán)色為服務(wù)器命令 粉色為配置文件
whereis nginx? #?查看 nginx位置
nginx: /usr/sbin/nginx(nginx位置) ? ?/usr/lib/nginx
/etc/nginx(配置文件位置) /usr/local/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
cd /etc/nginx? ? #?進(jìn)入配置文件
mkdir mysetconf? ?# 創(chuàng)建配置文件夾
cd mymysetconf
vim cxystar.com.conf??
# 修改如下配置內(nèi)容
server {
? ? listen 80;
? ? server_name cxystar.com;? ? ?# 服務(wù)名稱(chēng),建議使用網(wǎng)站名??
? ? location / {
? ? ? root /root/www.cxystar.com;? ? ? # root 項(xiàng)目文件路徑? 并不推薦在/root文件下
? ? ? index index.html index.htm;? ?? #? 在/root/www.cxystar.com下查找以下名字的文件,即項(xiàng)目html文件。
? ? }
}
# 接下來(lái)進(jìn)行配置文件的修改,修改之前記得備份
cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
vim nginx.conf
include /etc/nginx/conf.d/*.conf;? ? # 找到粉色這兩行修改
include /etc/nginx/mysetconf/*.conf;? ? ?# 修改為自己定義的配置文件夾
# 如果項(xiàng)目文件是存放root目錄下需要修改第一行的user,否則可以忽略
nginx -t? ?# 檢查語(yǔ)法是否正確
nginertx -s reload? ? # 重啟nginx服務(wù)

# 接下來(lái)進(jìn)行ssl證書(shū)的部署
cd /etc/nginx/mysetconf
mkdir cert? ? # 創(chuàng)建證書(shū)存放目錄 請(qǐng)?jiān)诖宋募A下放入.crt 和.key證書(shū)文件
cd cert? ?
vim cxystar.com.conf? ? # 創(chuàng)建配置文件
# 寫(xiě)入如下配置
server {
? ? listen 443 ssl;
? ? # 填寫(xiě)綁定證書(shū)的域名
? ? server_name cxystar.com; ? ?
? ? # 證書(shū)文件名稱(chēng)
? ? ssl_certificate vhosts/cert/www.cxystar.com_server.crt;
? ? # 私鑰文件名稱(chēng)
? ? ssl_certificate_key vhosts/cert/www.cxystar.com_server.key;
? ? ssl_session_timeout 30m;
? ? ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
? ? ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
? ? ssl_prefer_server_ciphers on;
? ? location / {
? ? ? ? root /root/www.cxystar.com;
? ? ? ? index index.html index.htm;
? ? }
}
server {
? ? listen 80;
? ? server_name cxystar.com;
? ? rewrite ^(.*) https://$server_name$1 permanent;
? ? location / {
? ? ? ? root /root/www.cxystar.com;
? ? ? ? index index.html index.htm;
? ? }
}
nginx -t? ? # 檢查語(yǔ)法是否正確
nginx -s reload? ?# 重啟nginx服務(wù)

輸入https://www.cxystar.com
