复制代码
如果这个下载太慢可以在这里下载http://nginx.org/download/nginx-1.9.5.tar.gz 下载完后yum -y intall lrzsz 装好上传工具
然后用rz上传到服务器
然后解压文件.
- tar zxvf nginx-1.9.5.tar.gz
复制代码
进入 nginx1.9.5的源码 如果想改版本号 可以进入源码目录
src/core/nginx.h
更改
- cd nginx-1.9.5/
复制代码
创建一个nginx目录用来存放运行的临时文件夹
- mkdir -p /var/cache/nginx
复制代码
开始configure
- ./configure \
- –prefix=/usr/local/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=nobody \
- –group=nobody \
- –with-pcre \
- –with-http_v2_module \
- –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-http_v2_module \
- –with-threads \
- –with-stream \
- –with-stream_ssl_module
复制代码
接着 编译
- make
复制代码
安装
- make install
复制代码
启动nginx
- /usr/sbin/nginx
复制代码
用ps aux来查看nginx是否启动
- ps aux|grep nginx
复制代码
然后配置服务
- vim /usr/lib/systemd/system/nginx.service
复制代码
按i输入以下内容
- [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=/var/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
复制代码
编辑好后保存
然后开启开机启动
- systemctl enable nginx.service
复制代码
用命令关掉nginx
- pkill -9 nginx
复制代码
后面可以用systemctl来操作nginx.service
- systemctl start nginx.service