时间:2023-02-09 03:33:01 | 来源:建站知识
时间:2023-02-09 03:33:01 来源:建站知识
原文来自将博客放在自己的 VPS 上,免不了配置 nginx 及 https,如果不配置 https,浏览器上
不安全
那三个字,实在是太刺眼。所以这篇博客,将记录整个折腾过程。apt install nginx
mkdir /etc/nginx/ssl
创建目录。<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
所有配置结束,可以访问自己的域名测试一下。关键词:配置