1. 常用命令
nginx -s stop 快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。
nginx -s quit 平稳关闭Nginx,保存相关信息,有安排的结束web服务。
nginx -s reload 因改变了Nginx相关配置,需要重新加载配置而重载。
nginx -s reopen 重新打开日志文件。
nginx -c filename 为 Nginx 指定一个配置文件,来代替缺省的。
nginx -t 不运行,仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。
nginx -v 显示 nginx 的版本。
nginx -V 显示 nginx 的版本,编译器版本和配置参数。
Windows下可编写一个批处理文件一键运行nginx
@echo off
rem 如果启动前已经启动nginx并记录下pid文件,会kill指定进程
nginx.exe -s stop
rem 测试配置文件语法正确性
nginx.exe -t -c conf/nginx.conf
rem 显示版本信息
nginx.exe -v
rem 按照指定配置去启动nginx
nginx.exe -c conf/nginx.conf
2. 配置文件
conf/nginx.conf 是 nginx 的默认配置文件
worker_processes 1; # Nginx 进程数,一般设置为和 CPU 核数一样
events {
worker_connections 1024; # 每个进程允许最大并发数
}
http {
include mime.types; # 文件扩展名与类型映射表
default_type application/octet-stream;
sendfile on; # 开启高效传输模式
keepalive_timeout 65; # 保持连接的时间,也叫超时时间,单位秒
server {
listen 8080; # 配置监听的端口
server_name localhost; # 配置的域名
location / {
root html; # 网站根目录
index index.html index.htm; # 默认首页文件
}
error_page 500 502 503 504 /50x.html; # 默认50x对应的访问页面
location = /50x.html {
root html;
}
}
include servers/*; # 加载子配置项
}