CentOS部署nginx

一、安装nginx所需要的环境

# c编译器
yum -y install gcc gcc-c++ autoconf automake make
# 解析正则的pcre库
yum install -y pcre pcre-devel
# 添加对gzip的支持
yum install -y zlib zlib-devel
# SSL
yum -y install pcre  pcre-devel zlib  zlib-devel openssl openssl-devel

二、下载nginx

[root@bogon src]# cd /usr/local/src/
[root@bogon src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
#压安装包
[root@bogon src]# tar zxvf nginx-1.6.2.tar.gz
#进入安装包目录
[root@bogon src]# cd nginx-1.6.2
#编译安装
[root@bogon nginx-1.6.2]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
[root@bogon nginx-1.6.2]# make
[root@bogon nginx-1.6.2]# make install
#查看nginx版本
[root@bogon nginx-1.6.2]# /usr/local/nginx/sbin/nginx -v


三、启动命令

#启动
[root@bogon conf]# /usr/local/nginx/sbin/nginx
#重新载入配置文件
[root@bogon conf]# /usr/local/nginx/sbin/nginx -s reload
# 重启 Nginx
[root@bogon conf]# /usr/local/nginx/sbin/nginx-s reopen
# 停止 Nginx
[root@bogon conf]# /usr/local/nginx/sbin/nginx-s stop

四、开机启动

1、创建nginx.service文件

vi /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

2、开机启动

systemctl enable nginx.service

3、启动服务

systemctl start nginx.service
systemctl start nginx.service (启动nginx服务)
systemctl stop nginx.service (停止nginx服务)
systemctl enable nginx.service (设置开机自启动)
systemctl disable nginx.service (停止开机自启动)
systemctl status nginx.service (查看服务当前状态)
systemctl restart nginx.service (重新启动服务)
systemctl list-units --type=service (查看所有已启动的服务)

你可能感兴趣的:(centos,nginx,运维)