nginx1.14.2部署
nginx 官网 http://nginx.org/download
一:下载
二:配置
三:启动
一:下载
wget http://nginx.org/download/nginx-1.14.2.tar.gz
2.安装依赖
yum install pcre pcre-devel openssl openssl-devel zlib zlib-devel -y
3.解压
解压并安装nginx(注意定制的安装路径根据自己的需求自行更改 ):
tar -zxvf nginx-1.14.2.tar.gz && cd nginx-1.14.2/
二:配置
4.配置(注意,一定要进入到nginx目录中去 --prefix的可以理解为编译指定的到具体的data目录,跟解压后的nginx压缩包的路径没关系)
nginx模块编译如果用不到那么多模块,可以不用,组件多了,容易被攻击。
编译:
./configure --prefix=/data/nginx --http-client-body-temp-path=/data/nginx/cache/nginx/client_temp --http-proxy-temp-path=/data/nginx/cache/nginx/proxy_temp --http-fastcgi-temp-path=/data/nginx/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/data/nginx/cache/nginx/uwsgi_temp --http-scgi-temp-path=/data/nginx/cache/nginx/scgi_temp --user=forest --group=forest --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-pcre --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
make && make install
5.添加环境变量到系统:
vim /etc/profile.d/nginx.sh
PATH=$PATH:/data/nginx/bin/:/data/nginx/sbin
source /etc/profile
6.添加启动脚本
### 3.1 编写nginx启动脚本:
[root@localhost ~]# vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/data/nginx/sbin/nginx
ExecReload=/data/nginx/sbin/nginx -s reload
ExecStop=/data/nginx/sbin/nginx -s quit
PrivateTmp=true
#EnvironmentFile=/etc/sysconfig/rdisc
#ExecStart=/sbin/rdisc $RDISCOPTS
[Install]
WantedBy=multi-user.target
### 3.2 添加开启启动:
systemctl enable nginx
三:启动
启动
3.3 查看nginx服务状态:
systemctl start nginx
systemctl status nginx
参考文章:
https://www.cnblogs.com/zhenxing06/p/12706897.html