Nginx是一个高性能的HTTP和反向代理服务器,以下是启用Nginx的基本步骤:
Ubuntu/Debian:
sudo apt update
sudo apt install nginx
CentOS/RHEL:
sudo yum install epel-release
sudo yum install nginx
# 启动Nginx
sudo systemctl start nginx
# 设置开机自启
sudo systemctl enable nginx
sudo systemctl status nginx
打开浏览器访问服务器IP地址或域名,应该能看到Nginx欢迎页面。
或者使用命令行:
curl -I 127.0.0.1
停止Nginx:
sudo systemctl stop nginx
重启Nginx:
sudo systemctl restart nginx
重新加载配置(不中断服务):
sudo systemctl reload nginx
# 允许HTTP(80)和HTTPS(443)流量
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
/etc/nginx/nginx.conf
/etc/nginx/conf.d/
或 /etc/nginx/sites-available/
/usr/share/nginx/html
修改配置后记得测试配置语法是否正确:
sudo nginx -t
如果遇到端口冲突(如80端口被占用),需要先停止占用该端口的服务。
在生产环境中,建议配置SSL/TLS证书以启用HTTPS。