通过源码安装的nginx的配置文件在安装目录/conf/nginx.conf
通过yum安装的nginx的配置文件在/etc/nginx/nginx.conf和 /etc/nginx/conf.d/*.conf
1、配置文件
主配置文件:
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" "$http_x_forwarded_for"‘; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
拆分配置文件:
server { listen 80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; }
location /my {
alias /opt/html/;
index index.html;
}
#root响应的路径:root配置的路径+location配置路径+静态文件
#alias响应的路径:root配置的路径+静态文件
#注意:
#1.使用alias时目录名后面一定要加“/”
#2.一般情况下,在location /中配置root,在location /other中配置alias
#3.root模块可以在location和server域下配置,而alias只能出现在location域。
#error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; }
2、运维命令
可以通过nginx -h查看命令帮助
这里比较常用的是nginx -s 命令,可用于操作已经启动的nginx进程。
nginx -s stop 执行后直接结束nginx进程。 nginx -s quit 执行后停止接受新请求,处理完毕现有请求后,再关闭nginx进程,也称优雅的停止。 nginx -s reload 不中断服务的情况下重载配置文件。 nginx -s reopen 重新打开一个日志文件,实现日志分割。
原文:https://www.cnblogs.com/huang99882008/p/10505834.html