centos7.4编译安装nginx

1、安装准备环境

yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel pcre*

下载pcre 

wget https://jaist.dl.sourceforge.net/project/pcre/pcre/8.42/pcre-8.42.zip

unzip pcre-8.42.zip -d /usr/local/src/

2、创建nginx运行用户

useradd -M -s /sbin/nologin nginx

3、下载nginx

http://nginx.org/download/选择自己需要安装的nginx版本

#下载
[root@localhost ~]wget http://nginx.org/download/nginx-1.16.0.tar.gz
#解压到指定目录
[root@localhost ~]tar zxf nginx-1.16.0.tar.gz -C /usr/local/src/

4、编译安装

[root@localhost ~]cd /usr/local/src/nginx-1.16.0
#编译安装
[root@localhost nginx-1.16.0]
./configure  
--prefix=/usr/local/nginx  
--sbin-path=/usr/local/nginx/sbin/nginx 
--conf-path=/usr/local/nginx/conf/nginx.conf
--user=nginx 
--group=nginx 
--with-http_ssl_module 
#以下参数根据自己需求,一般会有默认,本人没有选择
--error-log-path=/var/log/nginx/error.log  
--http-log-path=/var/log/nginx/access.log  
--pid-path=/var/run/nginx/nginx.pid 
--lock-path=/var/lock/nginx.lock  
--add-module=/usr/local/nginx/fastdfs-nginx-module/src
--with-http_stub_status_module 
--with-http_gzip_static_module 
--http-client-body-temp-path=/var/tmp/nginx/client/ 
--http-proxy-temp-path=/var/tmp/nginx/proxy/ 
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ 
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi 
--http-scgi-temp-path=/var/tmp/nginx/scgi 
--with-pcre

###参数说明 START###
--prefix 用于指定nginx编译后的安装目录
--add-module 为添加的第三方模块,如添加FastDFS的nginx模块
--with..._module 表示启用的nginx模块,如http_ssl_module模块
###参数说明 END###

[root@localhost nginx-1.16.0] make && make install

5、检查配置

[root@localhost ~]/usr/local/nginx.sbin/nginx -t

6、启动并检查是否成功,出现下图则已经安装成功

(1)启动nginx

#启动
[root@localhost ~]/usr/local/nginx.sbin/nginx
#停止
[root@localhost ~]/usr/local/nginx.sbin/nginx -s stop
#重载配置
[root@localhost ~]/usr/local/nginx.sbin/nginx -s reload

(2)检查nginx对应的端口是否成功启动

[root@localhost ~]lsof -i:80

0616c1f732fe4cfc8f5f08f0e9e1b806549.jpg

(3)检查nginx启动效果

[root@localhost ~]curl 127.0.01

86aa05b332babc4ea6b3cdea9f09cd241e9.jpg

7、查看nginx编译时的参数

[root@localhost ~]/usr/local/nginx.sbin/nginx -V

1a50c1b68b30f9ee985f86f612ebc14ede9.jpg

8、nginx 软件功能模块说明官方文档   http://nginx.org/en/docs/ngx_core_module.html

9、VMware虚拟机中安装Nginx后本机无法访问的解决办法

在虚拟机中配置了网站,用curl可以访问到,但是在本机却无法访问。

原因:没有开启80端口

解决办法:

[root@localhost ~]firewall-cmd --zone=public --add-port=80/tcp --permanent
#命令含义:
#–zone #作用域
#–add-port=80/tcp #添加端口,格式为:端口/通讯协议
#–permanent #永久生效,没有此参数重启后失效
[root@localhost ~]systemctl restart firewalld.service

猜你喜欢

转载自blog.csdn.net/qq_38157006/article/details/89952560