1、下载:nginx-1.12.2.tar.gz
https://nginx.org/en/download.html
2、上传到/usr/local
利用lrzsz工具,winscp或其他传输工具
3、安装依赖的软件库
(1) gcc
$ yum install gcc
(2)pcre-devel
$ yum install -y pcre pcre-devel
(3)zlib-devel
$ yum install -y zlib zlib-devel
(4)openssl-devel
$ yum install -y openssl openssl-devel
4、解压
$ tar -zxvf nginx-1.12.2.tar.gz
5、配置
$ cd nginx-1.12.2
$ ./configure
①使用默认配置(这里使用默认配置)
./configure
②自定义配置
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--pid-path=/usr/local/nginx/conf/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
注: 将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录
6、编译安装
$ make
$ make install
7、查找安装路径并进入
$ whereis nginx
$ cd ../nginx
8、启动停止、重新加载配置文件
$ cd sbin/
启动:
$ ./nginx
停止:
$ ./nginx -s quit
重新加载配置文件:
$ ./nginx -s reload
9、测试
$ curl 127.0.0.1
出现如下html内容说明成功。
10、加入系统服务,开机自启
(1)配置自定义服务文件nginx.service
$ vi /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
(2)开机启动
$ systemctl enable nginx.service
(3)服务启动
关闭:$ systemctl stop nginx.service
启动:$ systemctl start nginx.service
重启:$ systemctl restart nginx.service
查看:$ systemctl status nginx.service
11、开放端口
如果远程无法访问,请开启80端口
$ firewall-cmd --permanent --zone=public --add-port=80/tcp
success
$ firewall-cmd --reload
Success
完毕。