1、搭建nginx之前先下载安装pcre函数库
pcre 下载地址 https://sourceforge.net/projects/pcre/ 下载最新的8.44版本
2、安装pcre
下载之后rz -be上传到虚拟机,进行解压到根目录下
tar zxvf pcre-8.44.tar.gz -C./
对当前文件夹授予全部读写权限
chmod 777 -R /root/pcre-8.44,
cd 进到pcre-8.44目录下,安装gcc插件
yum -y install gcc
yum -y install gcc-c++
初始化配置并安装
./configure
make&&make install
进入pcretest命令界面
./pcretest
ctrl+c 退出,PCRE安装成功
可查看pcre版本号
pcre-config --version
3、安装nginx
nginx下载地址 http://nginx.org/, 下载稳定版nginx-1.18.0版本,rz -be从本地上传压缩包到虚拟机
解压到根目录下
tar zxvf nginx-1.18.0.tar.gz -C ./
安装插件
yum install -y zlib-devel
进到nginx-1.18.0目录下并初始化安装配置
cd nginx-1.18.0
需要编译安装
./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --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_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'
可能出现的错误
错误1:./configure: error: the invalid value in --with-ld-opt="-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E"
解决方法:yum -y install redhat-rpm-config.noarch
错误2:./configure: error: the HTTP image filter module requires the GD library.
解决方法: yum -y install gd-devel
错误3:./configure: error: perl module ExtUtils::Embed is required
解决方法: yum -y install perl-devel perl-ExtUtils-Embed
错误4:./configure: error: SSL modules require the OpenSSL library.
解决方法:yum -y install openssl openssl-devel
错误5:./configure: error: the HTTP XSLT module requires the libxml2/libxslt
解决方法:yum -y install libxslt-devel
错误6:/configure: error: the GeoIP module requires the GeoIP library.
解决方法:yum -y install geoip-devel
错误7:/configure: error: the Google perftools module requires the Google perftools
解决方法:yum -y install gperftools-devel
make&&make install
安装成功
查看nginx版本号
nginx -v 或 nginx -V
4、打开nginx
cd /usr/sbin
./nginx
可能会出错
解决办法
useradd -s /sbin/nologin -M nginx
id nginx
/usr/local/nginx/sbin/nginx
mkdir -p /var/lib/nginx/tmp/client_body
cd /usr/sbin/
./nginx
查看端口号
netstat -nlpt
出现80端口说明启动成功
按照此次安装,nginx 配置文件在/etc/nginx/nginx.conf下
来源:oschina
链接:https://my.oschina.net/u/4267090/blog/4782906