Centos7 安装nginx

Nginx 是 C语言 开发,建议在 Linux 上运行。

yum安装

安装响应的nginx依赖

yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel

nginx源头

rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

然后

yum install -y nginx

Nginx配置路径:/etc/nginx/

  • PID目录:/var/run/nginx.pid os.bz/tag/nginx-pid/)
  • 错误日志:/var/log/nginx/error.log
  • 访问日志:/var/log/nginx/access.log
  • 默认站点目录:/usr/share/nginx/html

事实上,只需知道Nginx配置路径,其他路径均可在/etc/nginx/nginx.conf 以及/etc/nginx/conf.d/default.conf 中查询到。

systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl daemon-reload
systemctl enable nginx

这些就是基本操作。

离线安装

去官方下载tar包

wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure

默认配置的安装路径为/usr/local/nginx

可以在执行configure 时候更改

./configure --prefix=/usr/nginx

然后

make && make install

基本操作

cd /usr/local/nginx/sbin/
./nginx
./nginx -s stop
./nginx -s quit
./nginx -s reload

设置systemctl

首先

vim /usr/lib/systemd/system/nginx.service

加入如下内容

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

然后

chmod 754 /usr/lib/systemd/system/nginx.service

然后就可以玩了

systemctl start nginx.service