本文基于
ubuntu 18.04 Desktop
安装
sudo apt install nginx
安装成功,用浏览器访问localhost,会显示nginx的一个页面,表示ngin已经正确安装并运行起来
命令(可能需要sudo)
# 强制立即关闭,不建议做
nginx -s stop
# 正常关闭,会处理已经接到的请求,但不会接受新的请求
nginx -s quit
# 重新加载配置文件
nginx -s reload
# 重新打开日志文件nginx.pid
nginx -s reopen
# 检查配置文件是否有误,修改配置后先用这个命令检查
nginx -t
# 检查配置文件是否有误,会将配置文件内容打印
nginx -T
# 查看 nginx 版本
nginx -v
# 查看 nginx 版本和编译配置致信息
nginx -V
nginx服务
sudo systemctl enable nginx
sudo systemctl start nginx
sudo systemctl restart nginx
sudo systemctl stop nginx
sudo systemctl status nginx
确认服务是否开机启动
service --status-all
systemctl is-enabled nginx
配置解析
推荐把配置文件拆分开来,在/etc/nginx/conf.d/ 文件建立对应的域名配置文件,比如 /etc/nginx/conf.d/12.com.conf 可在conf文件名中带上端口号,如1080-3030-123.com.conf可表示123.对外com使用1080端口,转发到3030端口