Centos编译安装nginx

依赖关系

cat /etc/redhat-release
yum update -y
yum install -y gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel

groupadd nginx 创建组
useradd -g nginx nginx 创建用户及所属用户组

nginx安装目录:/etc/nginx
nginx配置文件目录:/usr/local/nginx/nginx.conf
nginx虚拟服务器配置目录:/usr/local/nginx/vhost/
log日志目录:/var/log/nginx/
pid文件目录:/var/run/nginx.pid
lock锁目录:/var/run/nginx.lock
临时缓存目录:/var/cache/nginx
站点目录:/www/wwwroot/
nginx运行用户名:nginx
nginx运行用户组:nginx

./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-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-stream_realip_module \
–with-stream_ssl_module \
–with-stream_ssl_preread_module

或者安装到一个目录:
./configure \
–prefix=/etc/nginx \
–sbin-path=/etc/nginx/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=/etc/nginx/sbin/nginx.pid \
–lock-path=/etc/nginx/sbin/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 \
–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-stream_realip_module \
–with-stream_ssl_module \
–with-stream_ssl_preread_module

chmod +x configure 添加权限

make && make install
make -j16 && make install

查看配置是否正确
/etc/nginx/sbin/nginx -t

# 启动
/etc/nginx/sbin/nginx
# 停止
/etc/nginx/sbin/nginx -s stop
# 平滑重新启动
/etc/nginx/sbin/nginx -s reload

#添加开启启动(根据编译目录修改脚本地址)
在 /etc/systemd/system/ 目录下编写脚本
vi /etc/systemd/system/nginx.service

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
PIDFile=/etc/nginx/sbin/nginx.pid
ExecStart=/etc/nginx/sbin/nginx
ExecReload=/etc/nginx/sbin/nginx -s reload
ExecStop=/etc/nginx/sbin/nginx -s stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

 

systemctl start nginx 启动
systemctl enable nginx 开机启动
systemctl restart nginx 重启
systemctl disable nginx 关闭开机启动

0

评论0

显示验证码