centos7下编译安装nginx

自行下载所需的nginx: http://nginx.org/download
我这里用的是1.9.9

1
2
3
wget http://nginx.org/download/nginx-1.9.9.tar.gz
tar -xvzf nginx-1.9.9.tar.gz
cd nginx-1.9.9

编译所需要的环境以及部分依赖组件

1
2
yum install gcc gcc-c++
yum install zlib zlib-devel openssl openssl-devel pcre pcre-devel

新建一个系统级用户组和匿名用户

1
2
groupadd -r nginx
useradd -s /sbin/nologin -g nginx -r nginx

然后开始编译
所用到的参数仅供参考,还有本人常用的mod

1
./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-threads --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_v2_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed' --with-ipv6 --add-module=/root/nginx_mod/ngx_http_substitutions_filter_module --add-module=/root/nginx_mod/nginx-http-concat --add-module=/root/nginx_mod/nginx-http-footer-filter-1.2.2

安装

1
$ make && make install

你也可以在末尾添加mod,格式如下

1
--add-module=/root/nginx_mod/nginx-http-concat

上面的的编译用到了三个mod,还有下载地址
ngx_http_substitutions_filter_module:https://github.com/yaoweibin/ngx_http_substitutions_filter_module
nginx-http-concat:https://github.com/alibaba/nginx-http-concat
nginx-http-footer-filter-1.2.2:https://github.com/alibaba/nginx-http-footer-filter/tree/1.2.2
都是本人觉得挺好用的,推荐推荐~~~~

添加服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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=/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 -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

开机启动

1
systemctl enable nginx.service

添加评论