在 PVE 宿主机安装 Nginx 并修改默认页

发表于 2025-09-05 19:35:22 分类于 默认分类 阅读量 138

在 PVE 宿主机安装 Nginx 并修改默认页

Proxmox VE(PVE)宿主机也可以安装 Nginx,用来托管网站或做反向代理。本文介绍在 PVE 宿主机上安装 Nginx、启动服务,并修改默认页面的方法。


1. 系统更新

首先更新系统:

apt update && apt upgrade -y

2. 安装 Nginx

apt install nginx -y

3. Nginx 服务管理常用命令

启动 Nginx

systemctl start nginx

停止 Nginx

systemctl stop nginx

重启 Nginx

systemctl restart nginx

重新加载配置(不中断服务)

systemctl reload nginx

查看 Nginx 状态

systemctl status nginx

设置开机自启动

systemctl enable nginx

关闭开机自启动

systemctl disable nginx

立即启动并设置开机自启

systemctl enable nginx --now

4. 检查 Nginx 服务

systemctl status nginx

5. 配置防火墙(可选)

如果启用了 PVE 防火墙,允许 80 和 443 端口:

pve-firewall local rule add accept proto tcp dport 80
pve-firewall local rule add accept proto tcp dport 443
pve-firewall reload

6. 测试访问

在浏览器访问:

http://宿主机IP/

会看到默认的 Nginx 欢迎页。


7. 修改默认页

方法一:直接修改 index 文件

默认网页文件位置:

/var/www/html/index.nginx-debian.html

编辑文件:

nano /var/www/html/index.nginx-debian.html

修改 HTML 内容,例如:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>我的网站</title>
</head>
<body>
    <h1>欢迎访问我的网站!</h1>
</body>
</html>

保存后重新加载 Nginx:

systemctl reload nginx

刷新浏览器即可。

方法二:修改默认站点根目录

  1. 创建新目录:
mkdir -p /var/www/my_site
nano /var/www/my_site/index.html
  1. 编辑默认站点配置:
nano /etc/nginx/sites-available/default

修改:

root /var/www/my_site;
index index.html;
  1. 检查配置并重载 Nginx:
nginx -t
systemctl reload nginx

刷新浏览器,新默认页生效。


8. 其他实用命令

查看 Nginx 进程

ps aux | grep nginx

查看 Nginx 版本

nginx -v

查看详细的版本和编译信息

nginx -V

测试配置文件语法

nginx -t

查看 Nginx 错误日志

tail -f /var/log/nginx/error.log

查看 Nginx 访问日志

tail -f /var/log/nginx/access.log

9. 建议

  • 推荐在 PVE 中创建 LXC 容器或虚拟机安装 Nginx,这样更安全、易管理。
  • 避免直接在宿主机上修改系统文件,避免影响 PVE 管理面板。
  • 修改配置后务必使用 nginx -t 测试语法,然后使用 systemctl reload nginx 重新加载配置。
正物博客
一路向前,山海自平