当前位置:文档之家› nginx配置安装文档

nginx配置安装文档

nginx 安装调试

1、检查是否安装了nginx

find -name nginx

如果安装了,删除 nginx目录即可完成卸载。如果配置了自启动,也需要删除


2、选择src目录作为源文件目录,并进入src目录
cd /usr/local/src

3、安装gcc-c++
yum install gcc-c++

4、安装pcre和pcre-devel
yum install -y pcre pcre-devel

5、安装zlib 和zlib-devel
yum install -y zlib zlib-devel
6、安装openssl 和 openssl-devel
yum install -y openssl openssl-devel

7、下载nginx源码包
wget https://www.doczj.com/doc/2016550759.html,/download/nginx-1.12.2.tar.gz

8、解压压缩文件
tar -xzvf nginx-1.12.2.tar.gz

9、切换到nginx-1.12.2目录
cd /usr/local/nginx-1.12.2

10、配置 Nginx 安装选项
./configure (默认选项,一般用它即可)

自定义配置:
./configure\
--with-http_ssl_module\
--with-http_v2_module\
--with-http_realip_module\
--with-http_addition_module\
--with-http_xslt_module\
--with-http_image_filter_module\
--with-http_sub_module\
--with-http_auth_request_module\
--with-http_stub_status_module\
--with-http_gzip_static_module

#实现图片的处理
--with-http_image_filter_module\
#指定相关参数的文件路径,注意:如果携带如下参数,安装之前需要手动创建上面指定的nginx文件夹,即/var/temp、/var/temp/nginx、/var/run/nginx/文件夹,否则启动时报错

--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi

完整配置范例:
 ./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--with-http_ssl_module\
--with-http_v2_module\
--with-http_realip_module\
--with-http_addition_module\
--with-http_xslt_module\
--with-http_image_filter_module\ #实现图片的处理
--with-http_sub_module\
--with-http_auth_request_module\
--with-http_stub_status_module\
注意:安装之前需要手动创建上面指定的nginx文件夹,即/var/temp、/var/temp/nginx、/var/run/nginx/文件夹,否则启动时报错

11、编译Nginx
make && make install


12、配置 systemd Nginx 服务和设置 Nginx 自启动
centos 7 中采用 systemd 来管理系统,我们来为 nginx 创建服务文件,来实现通过 systemd 来管理 nginx。
创建 systemd 服务文件: /lib/systemd/system/nginx.service ,内容如下:

[Unit]
Description=The NGINX HTTP and reverse proxy se

rver
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

13、设置nginx服务自启动
systemctl enable nginx

14、常用管理nginx命令

systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl reload nginx


相关主题
文本预览
相关文档 最新文档