# 安装 Nginx

apt update
apt install nginx

nginx 安装目录: /etc/nginx/ ,配置文件目录: /etc/nginx/nginx.conf ,网站的 nginx 配置文件一般单独放于 nginx 目录下的 conf.d 文件夹

# 配置网站 Server

配置样例

server {
		server_name YOUR_SERVER_NAME;
		listen 80;
		listen 443 ssl;
		
		if ($scheme != https) {
			rewrite ^/(.*) https://$server_name/$1 permanent;
			}
		if ($http_x_forwarded_proto = "http") {
			return 301 https://$server_name$request_uri;
			}
		ssl_certificate /etc/letsencrypt/live/YOUR_DOMAIN_NAME/fullchain.pem; // 域名证书位置
		ssl_certificate_key /etc/letsencrypt/live/YOUR_DOMAIN_NAME/privkey.pem;
		ssl_session_timeout  5m;
		ssl_ciphers HIGH:!aNULL:!MD5:!kEDH;
		ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
		
		root /www/hexo;
		index index.html index.htm; 
		
	}

申请域名 SSL 证书过程请至:申请 Let’s Encrypt 证书

# Nginx 常用命令

  • 安装
apt update
apt install nginx
  • 启动
sudo systemctl start nginx
  • 停止
sudo systemctl stop nginx
  • 重载
sudo systemctl reload nginx
  • 卸载
sudo apt purge nginx
sudo apt purge nginx-common
sudo apt purge nginx-core
  • 清除配置文件
sudo rm -rf /etc/nginx
更新于