一.环境
名称 | 版本号 |
---|---|
CentOS | 7.x |
Nginx | 1.16.0 |
二.安装&配置
- 首先在虚拟机中需要关闭防火墙,否则访问不了
开机不自动启动防火墙 sudo systemctl disable firewalld.service 关闭防火墙 sudo systemctl stop firewalld.service
- 由于是新的环境,需要预先安装一些依赖
yum install gcc-c++
yum install -y pcre pcre-devel #pcre库 用于解析正则
yum install -y zlib zlib-devel #zlib压缩解压
yum install -y openssl openssl-devel #https相关 - 先将本地的nginx传入到虚拟服务器中并且解压
tar -zvxf nginx-1.16.0.tar.gz
- 创建nginx临时目录,如果不创建,再启动nginx时候会报错
mkdir /var/temp/nginx -p
- 进入解压后的nginx文件夹,先进行配置
./configure –with-http_auth_request_module –with-http_realip_module –with-http_v2_module –with-debug –add-module=/home/web/nginx-http-concat/ –with-http_random_index_module –with-http_sub_module –with-http_addition_module –with-http_secure_link_module –with-http_geoip_module –with-http_ssl_module –with-stream_ssl_module –with-stream_realip_module –with-stream_ssl_preread_module –with-stream –add-module=/home/web/ngx_cache_purge/ –with-http_slice_module –with-google_perftools_module –with-threads –with-ld-opt=-ltcmalloc –with-http_gzip_static_module –with-http_gunzip_module –with-http_stub_status_module
- 编译和安装
make & make install
- 等编译安装完毕后,就可以去
/usr/local/nginx/sbin/
文件夹下启动了./nginx #启动 ./nginx -s stop #停止 ./nginx -s reload #重新加载
- 最后查看是否启动成功
ps -ef | grep nginx