安装
yum install -y nginx
若提示无可用软件,执行下边添加软件源
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
再执行
yum install -y nginx
查看ngibx相关路劲信息
whereis nginx
(1) Nginx配置路径:/etc/nginx/
(2) PID目录:/var/run/nginx.pid
(3) 错误日志:/var/log/nginx/error.log
(4) 访问日志:/var/log/nginx/access.log
(5) 默认站点目录:/usr/share/nginx/html
事实上,只需知道Nginx配置路径,其他路径均可在/etc/nginx/nginx.conf 以及/etc/nginx/conf.d/default.conf 中查询到。
安装目录下命令重启、停止、开启Nginx 相关指令
cd /usr/sbin
./nginx nginx --启动Nginx
./nginx -s stop --关闭Ngix
./nginx -s reload --重加载Nginx [修改配置文件后,必须执行,否则不生效]
测试Nginx配置是否正确:
nginx -t
开启 80 端口
sudo firewall-cmd --add-port=80/tcp --permanent
重启防火墙,使增加的端口生效
firewall-cmd --reload
#我们要想执行Nginx命令,就必须进入 红圈 内的路径,
查看nginx版本
查看Nginx 的版本信息
cd /usr/sbin
./nginx -v
#修改Nginx配置
cd /etc/nginx
vim nginx.conf
设置Nginx服务自启动
#在 /lib/systemd/system 目录添加 nginx.service 文件
vim /lib/systemd/system/nginx.service
#编辑自启文件
#添加以下内容, Restart=always
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if/run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
Restart=always
[Install]
WantedBy=multi-user.target
设置开机启动
systemctl enable nginx
启动 nginx
systemctl start nginx
停止
systemctl stop nginx
加载配置文件
systemctl reload nginx