時間:2023-02-09 03:33:01 | 來源:建站知識
時間:2023-02-09 03:33:01 來源:建站知識
原文來自將博客放在自己的 VPS 上,免不了配置 nginx 及 https,如果不配置 https,瀏覽器上
不安全
那三個字,實在是太刺眼。所以這篇博客,將記錄整個折騰過程。apt install nginx
mkdir /etc/nginx/ssl
創(chuàng)建目錄。<h1>Hello iMoegirl</h1>
rm /etc/nginx/sites-enabled/default
vim /etc/nginx/conf.d/imoegirl.com.conf
# 下面這段,是將 http 重定向到 https,不管帶不帶 wwwserver { listen 80 default_server; listen [::]:80 default_server; server_name _; return 301 https://imoegirl.com$request_uri;}# 下面這一段,是處理帶 www 的域名# 最后會重定向到 不帶 www 域名server { listen 443 ssl http2; server_name www.imoegirl.com; ssl_certificate /etc/nginx/ssl/imoegirl.com.crt; ssl_certificate_key /etc/nginx/ssl/imoegirl.com.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; keepalive_timeout 70; root /var/www/imoegirl.com; index index.html index.htm index.nginx-debian.html; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } return 301 https://imoegirl.com$request_uri;}# 下面這一段,是處理不帶 www 的域名,也就是最終我們想要的server { listen 443 ssl http2; server_name imoegirl.com; ssl_certificate /etc/nginx/ssl/imoegirl.com.crt; ssl_certificate_key /etc/nginx/ssl/imoegirl.com.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; keepalive_timeout 70; root /var/www/imoegirl.com; index index.html index.htm index.nginx-debian.html; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; }}
上面的代碼,注意幾個地方service nginx restart
所有配置結(jié)束,可以訪問自己的域名測試一下。關(guān)鍵詞:配置
微信公眾號
版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。