1. Install Nginx:
sudo yum install epel-release # 安装EPEL仓库
sudo yum install nginx # 安装Nginx
2. Start the Nginx service:
sudo systemctl start nginx # 启动Nginx服务
sudo systemctl enable nginx # 设置Nginx开机自启
3. Configure firewall rules (if required):
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent # 开放HTTP 80端口
sudo firewall-cmd --reload # 重新加载防火墙配置
4. Configure Nginx virtual host:
# 编辑Nginx配置文件
sudo vi /etc/nginx/nginx.conf
# 在http块中添加以下内容
server {
listen 80;
server_name your_domain.com; # 替换为你的域名或IP地址
location / {
root /path/to/your/webapp; # 替换为你的Web应用程序的根目录
index index.html index.htm;
}
}
5. Check whether the Nginx configuration file is correct:
sudo nginx -t
6. Reload Nginx configuration:
sudo systemctl reload nginx
7. At this time, when you access the domain name, 403 Forbidden will appear. You still need to take one step here.
# 再一次编辑Nginx配置文件
sudo vi /etc/nginx/nginx.conf
# 将第一行的权限改为root即可,大功告成,即可访问网页
user root;