- 源码安装
(1)源码包的获取
http://nginx.org/download/
源码安装的环境说明:
系统:CentOS 7.4
软件:nginx-1.14.0.tar.gz
其他所需软件:openssl-1.0.2d.tar.gz、pcre-8.37.tar.gz、zlib-1.2.8.tar.gz
安装方式:源码编译安装
安装位置:/opt/data/nginx
下载地址:http://nginx.org/download
(2)安装环境准备,安装依赖包,创建安装目录
[root@localhost ~]# mkdir -p /opt/data/nginx/
[root@localhost ~]# groupadd nginx
[root@localhost ~]# useradd -g nginx nginx
[root@localhost ~]# yum install gcc gcc-c++ make recp pcre-devel openssl openssl-devel -y
[root@localhost ~]# tar -xf nginx-1.14.0.tar.gz -C /usr/local/src/
(3)编译安装
[root@localhost nginx-1.14.0]# ./configure \
> --prefix=/opt/data/nginx \
> --with-http_stub_status_module \
> --with-http_ssl_module \
> --with-stream
[root@localhost nginx-1.14.0]# make &make install
(4)配置环境变量
[root@localhost sbin]# ./nginx -t
[root@localhost sbin]# vim /etc/profile.d/nginx.sh
export PATH=/opt/data/nginx/sbin:$PATH
[root@localhost sbin]# source /etc/profile.d/nginx.sh
(5)Nginx配置
[root@localhost nginx]# ln -s /opt/data/nginx/conf /etc/nginx
[root@localhost nginx]# vim nginx.conf
user nginx;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
access_log off;
client_max_body_size 128M;
include /etc/nginx/conf.d/*.conf;
}
[root@localhost nginx]# mkdir /etc/nginx/conf.d
[root@localhost nginx]# mkdir /var/log/nginx
[root@localhost nginx]# chown -R nginx:nginx /var/log/nginx
(6)Nginx启动
vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/opt/data/nginx/sbin/nginx -t -c /opt/data/nginx/conf/nginx.conf
ExecStart=/opt/data/nginx/sbin/nginx -c /opt/data/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost conf]# systemctl enable nginx