在 Linux 上“重置 Nginx 配置”通常有几种不同含义,下面按常见场景给你说明,你可以按需选择。
如果你改乱了配置,想恢复到刚安装时的默认状态:
cp -r /etc/nginx /etc/nginx.bak
rm -rf /etc/nginx/*
不同系统方式略有不同:
apt-get install --reinstall nginx-common
yum reinstall nginx
# 或
dnf reinstall nginx
nginx -t
systemctl restart nginx
如果你只是某个 site 配置写错了:
cd /etc/nginx/sites-available
rm your_site.conf
然后重新创建或复制默认配置:
cp default your_site.conf
启用并重启:
ln -s /etc/nginx/sites-available/your_site.conf /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginx
如果默认配置被删了,可以手动重建一个最小配置:
/etc/nginx/nginx.confuser www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80;
server_name localhost;
location / {
root /var/www/html;
index index.html;
}
}
}
然后:
nginx -t
systemctl restart nginx
systemctl stop nginx
apt purge nginx nginx-common # Ubuntu
# 或
yum remove nginx # CentOS
rm -rf /etc/nginx
apt install nginx
# 或
yum install nginx
nginx -t
restart 时可以先:systemctl reload nginx
/etc/nginx//etc/nginx/如果你能告诉我:
我可以给你更精确的一步到位命令。