主机系统:Debian
一、安装nginx
apt update
apt install nginx
二、配置nginx
tip须知
nginx中sites_available目录:存储网站配置文件,但这里的配置文件不会生效
nginx中sites_enabled目录:包含实际生效的网站配置,这里的文件是sites_available中文件的符号连接,nginx只会读取这个目录中的配置文件
这样的优势是:快速启用/禁用网站,只需要删除符号链接即可,不用改动配置文件
#创建配置文件
cd /etc/nginx/sites-available/
touch your_domain
#编辑配置文件
vim your_domain
{
listen port;
server_name: your_domain.com www.your_domain.com;
location /test {
alias /var/www/html
}
}
#创建符号连接到sites_enabled
ln -s /etc/nginx/sites_available/your_domain /etc/nginx_sites/sites_enabled/
#验证nginx语法是否正确
nginx -t
#重启nginx
systemctl restart nginx
浏览器访问 http://your_domain.com/test,测试看下能否正常访问
三、获取SSL证书
apt install cerbot python3-cerbot-nginx
cerbot --nginx -d yourdomain.com -d www.yourdomain.com
#cerbot会自动重启nginx,不需要手动重启
浏览器访问 https://your_domain.com/test,测试看下能否正常访问
Keep reading with a 7-day free trial
Subscribe to moz’s 订阅 to keep reading this post and get 7 days of free access to the full post archives.