centos7下nginx的安装和启动

阿祖 2019-04-23 14:53:40 访问量: 151 TAG: nginx linux

安装依赖

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

创建用户

groupadd www
useradd -s /sbin/nologin -g www

安装nginx

cd /usr/local/src/
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar -zxvf nginx-1.14.2.tar.gz
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
make && make install

开机启动

新增文件

vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target

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

[Install]
WantedBy=multi-user.target

设置开机启动

systemctl enable nginx.service

测试运行

启动:

systemctl start nginx

重载:

systemctl reload nginx

停止:

systemctl stop nginx

状态:

systemctl status nginx

非特殊说明,本博所有文章均为博主原创。