Nginx 配置简述
Nginx 配置由 main、events、http、server、location 等上下文组成。先写最小可用配置,再按需加入模块指令。
最小完整配置
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 10240;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name _;
root /var/www/html;
index index.html;
}
}应用配置
sudo nginx -t
sudo nginx -s reload排错顺序
nginx -t:语法和文件读取。nginx -T:展开 include 后的完整配置。- 查看
error_log、systemd 状态和端口占用。