1、安装编译工具
yum -y install make zlib zlib-devel gcc gcc-c++ libtool openssl openssl-devel pcre pcre-devel ncurses-devel perl
2、创建用户
groupadd www
useradd -g www www -M -s /sbin/nologin
# -M参数表示不添加用户家目录,-s参数表示指定shell类型
3、安装Nginx
下载地址:http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz && cd nginx-1.8.0
./configure \
--prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-pcre \
--with-http_realip_module \
--with-http_sub_module
# –with-http_stub_status_module 启用 Nginx 的 NginxStatus 功能
make && make install
# 软链
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
nginx -v # 查看版本
netstat -ano|grep 80 # 检查80端口
nginx # 启动
nginx -t # 检查配置
查看Nginx所在网址
http://127.0.0.1
Welcome to nginx!
4、常用操作
nginx -s reload # 重新载入配置文件
nginx -s reopen # 重启 Nginx
nginx -s stop # 停止 Nginx
开机自启
vi /etc/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
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