1、安装编译环境
#yum install gcc-c++ -y
2、下载Nginx及相关组件
[root@localhost src]# wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
#tar zxvf openssl-fips-2.0.10.tar.gz
# cd openssl-fips-2.0.10
# ./config && make && make install
[root@localhost src]# wget http://zlib.net/zlib-1.2.11.tar.gz
# tar zxvf zlib-1.2.11.tar.gz
# cd zlib-1.2.11
# ./configure && make && make install
[root@localhost src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
#tar zxvf pcre-8.40.tar.gz
#cd pcre-8.40
#./configure && make && make install
[root@localhost src]# wget http://nginx.org/download/nginx-1.10.2.tar.gz
#tar zxvf nginx-1.15.5.tar.gz
#cd nginx-1.15.5
#./configure && make && make install
3、启动Nginx
进入nginx目录并启动
启动
[root@localhost ~]# /usr/local/nginx/sbin/nginx
停止/重启
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop(quit、reload)
命令帮助
[root@localhost ~]# /usr/local/nginx/sbin/nginx -h
验证配置文件
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
centos7中设置nginx的systemctl启动方式
(1)文件路径
vim /usr/lib/systemd/system/nginx.service
(2)服务文件内容
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.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 stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
[Install]
WantedBy=multi-user.target
#chmod 754 /usr/lib/systemd/system/nginx.service
然后执行(修改或新增文件需要执行以下语句才能生效)
#systemctl daemon-reload