1、安装必备工具:
yum -y install gcc gcc-c++ autoconf automake
yum -y install zlib zlib-devel openssl openssl-devel pcre-devel
说明:
pcre: 用来作地址重写的功能。
zlib:nginx 的gzip模块,传输数据打包,省流量(但消耗资源)。
openssl:提供ssl加密协议。
2、新建一个系统级用户组和匿名用户,以及下面编译时使用
groupadd -r nginx
useradd -s /sbin/nologin -g nginx -r nginx
3、下载nginx
wget
tar -zxvf nginx-1.9.7.tar.gz
cd nginx-1.9.7/
4、编译nginx
[root@localhost nginx-1.9.7]#
-
./configure \
-
--prefix=/etc/nginx \
-
--sbin-path=/usr/sbin/nginx \
-
--conf-path=/etc/nginx/nginx.conf \
-
--error-log-path=/var/log/nginx/error.log \
-
--http-log-path=/var/log/nginx/access.log \
-
--pid-path=/var/run/nginx.pid \
-
--lock-path=/var/run/nginx.lock \
-
--http-client-body-temp-path=/var/cache/nginx/client_temp \
-
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
-
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
-
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
-
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
-
--user=nginx \
-
--group=nginx \
-
--with-http_ssl_module \
-
--with-http_realip_module \
-
--with-http_addition_module \
-
--with-http_sub_module \
-
--with-http_dav_module \
-
--with-http_flv_module \
-
--with-http_mp4_module \
-
--with-http_gunzip_module \
-
--with-http_gzip_static_module \
-
--with-http_random_index_module \
-
--with-http_secure_link_module \
-
--with-http_stub_status_module \
-
--with-http_auth_request_module \
-
--with-mail \
-
--with-mail_ssl_module \
-
--with-file-aio \
-
--with-ipv6 \
-
--with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
[root@localhost nginx-1.9.7]# make -j4 && make install
[root@localhost nginx-1.9.7]# mkdir -p /var/cache/nginx/client_temp
[root@localhost nginx-1.9.7]# systemctl stop httpd.service
[root@localhost nginx-1.9.7]# nginx -c /etc/nginx/nginx.conf
5、Nginx 控制脚本
[root@localhost nginx-1.9.7]# gedit /usr/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=/run/nginx.pid
-
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
-
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
-
ExecReload=/bin/kill -s HUP ${MAINPID}
-
ExecStop=/bin/kill -WINCH ${MAINPID}
-
PrivateTmp=true
-
-
[Install]
-
WantedBy=multi-user.target
6、修改权限
[root@localhost nginx-1.9.7]# chmod +x /usr/lib/systemd/system/nginx.service
[root@localhost nginx-1.9.7]# systemctl enable nginx.service
ln -s '/usr/lib/systemd/system/nginx.service' '/etc/systemd/system/multi-user.target.wants/nginx.service'
# 会在/etc/systemd/system/multi-user.target.wants/目录下新建一个/usr/lib/systemd/system/nginx.service 文件的链接。
7、使用下面的指令来控制nginx
systemctl start nginx.service
systemctl reload nginx.service
systemctl restart nginx.service
systemctl stop nginx.service
8、查看日志
journalctl -f -u nginx.service
++++++++++++++++++++++++++++++++++
[root@localhost nginx]# gedit /etc/nginx/nginx.conf
阅读(1113) | 评论(0) | 转发(0) |