CentOS7源码安装Nginx及配置
一、安装
1、安装gcc gcc-c++
# yum install -y gcc gcc-c++
2、安装PCRE库
# cd /usr/local/
# mkdir pcre
# cd pcre
# wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.36/pcre-8.36.tar.gz
# tar -zxvf pcre-8.36.tar.gz
# cd pcre-8.36
# ./configure
# make && make install
# yum install -y pcre pcre-devel
3、安装zlib库
# cd /usr/local/
# mkdir zlib
# cd zlib
# 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
# yum install -y zlib zlib-devel
4、安装SSL库
# cd /usr/local/
# mkdir openssl
# cd openssl
# wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
# tar -zxvf openssl-1.0.1j.tar.gz
# cd openssl
# ./configure
# make && make install
# yum -y install openssl openssl-devel
5、安装nginx
# cd /usr/local/
# mkdir nginx
# cd nginx
# wget http://nginx.org/download/nginx-1.12.0.tar.gz
# tar -zxvf nginx-1.12.0.tar.gz
# cd nginx-1.12.0
# ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module
# make && make install
6、
启动
# /usr/local/nginx/sbin/nginx
重启
# /usr/local/nginx/sbin/nginx –s reload
停止
# /usr/local/nginx/sbin/nginx –s stop
退出
# /usr/local/nginx/sbin/nginx –s quit
测试配置文件是否正常
# /usr/local/nginx/sbin/nginx –t
7、添加为系统服务
vi /lib/systemd/system/nginx.service来添加nginx.service文件,并输入如下内容:
[Unit]
Description=nginx 1.13.7
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
#### 内容结束 ####
更改nginx.service为可执行:
# chmod 755 /lib/systemd/system/nginx.service
设置开机自启动:
# systemctl enable nginx.service
服务使用