一、nginx源码
(1)nginx获取
RPM包获取:http://nginx.org/packages/centos/7/x86_64/RPMS/
源码包获取:http://nginx.org/download/
(2)nginx的rpm包安装
yum localinstall nginx-1.10.0-1.el7.ngx.x86_64.rpm -y
rpm -ql nginx
---配置文件 /etc/nginx/nginx.conf
---主目录 /usr/share/nginx/html/
---查看版本 /usr/sbin/nginx -v
---配置文件语法检查 /usr/sbin/nginx -t
---服务启动停止 /etc/init.d/nginx (start|stop|restart|reload|status)
若需要gzip和rewrite的正则,需要安装zlib、zlib-devel、pcre。
(2)nginx源码安装
①、安装环境准备,安装依赖包,创建安装目录
mkdir -p /opt/data/nginx/
groupadd nginx
useradd -g nginx nginx
yum install gcc gcc-c++ make repc pcre-devel openssl openssl-devel -y
tar -xf nginx-1.14.0.tar.gz -C /usr/local/src/
②、编译安装
[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
③、配置环境变量
[root@localhost sbin]# ./nginx -t
nginx: the configuration file /opt/data/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /opt/data/nginx//conf/nginx.conf test is successful
[root@localhost sbin]# vim /etc/profile
export PAYH=/opt/data/nginx/sbin:$PATH
[root@localhost sbin]# source /etc/profile
④、nginx配置
[root@localhost nginx]# ln -s /opt/data/nginx/conf/ /etc/nginx
[root@localhost nginx]# vim nginx.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
[root@localhost nginx]# cat nginx.conf(/etc/nginx/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;
}
⑤、nginx启动
[root@localhost conf]# vim /lib/systemd/system/nginx.service
[root@localhost conf]# cat /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 restart nginx
⑥、关闭nginx的方法
(1)立刻停止nginx服务
/usr/local/nginx/sbin/nginx -s stop
(2)完成当前任务后停止
/usr/local/nginx/sbin/nginx -s quit
(3)杀死nginx进程
kill nginx