CENTOS7教程
+ -

Centos7 nginx 环境搭建

2019-09-09 5 0

安装nginx

  1. 下载nginx安装包
    wget http://nginx.org/download/nginx-1.11.12.tar.gz
    

2.解压并切换到解压目录

tar -xvf nginx-1.11.12.tar.gz
cd nginx-1.11.12

3.执行命令 ./configure
如出现如下错误:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

则进行安装:

yum -y install pcre-devel

4.执行命令 ./configure
如出现如下错误:

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

则进行安装:

 yum -y install zlib-devel

5.继续执行如下命令 configure —prefix=/usr/local/nginx —with-http_ssl_module

./configure --prefix=/usr/local/nginx  --with-http_ssl_module

如出现:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

则安装:

yum -y install openssl openssl-devel

6.执行 configure —prefix=/usr/local/nginx —with-http_ssl_module

./configure --prefix=/usr/local/nginx  --with-http_ssl_module

这时可以看到成功了

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

7.执行 make命令进行编译

make

执行结果如下:

...
objs/ngx_modules.o 
-ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lz 
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/nginx|" 
    -e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" 
    -e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" 
    -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" 
    < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/usr/local/nginx-1.11.12'

8.make编译成功后,执行make install进行安装

make install

执行结果如下:

cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' 
    || mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' 
    || mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' 
    || cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' 
    || mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory `/usr/local/nginx-1.11.12'

9.切换目录到 /usr/local/nginx/sbin

cd /usr/local/nginx/sbin
[root@localhost sbin]# ls
nginx

可以看到有个可执行的nginx文件

执行./nginx -v检查是否成功安装

[root@localhost sbin]# ./nginx -v
nginx version: nginx/1.11.12

10.启动nginx

/usr/local/nginx/sbin/nginx

启动后,在浏览器中输入服务器的IP地址,即可以看到
Welcome to nginx!
的字样

说明:

如果在远程电脑上输入ip地址可能会出现该页无法显示的情况,这是由于防火墙的原因,具体设置方法见 Centos 80端口防火增外放

nginx的其它操作项:
重启

/usr/local/nginx/sbin/nginx –s reload

停止

/usr/local/nginx/sbin/nginx –s stop

测试配置文件是否正常:

 /usr/local/nginx/sbin/nginx –t

强制关闭

$ pkill nginx

开机自启动

即在rc.local增加启动代码就可以了。

vi /etc/rc.local

增加一行

/usr/local/nginx/sbin/nginx

设置执行权限:

chmod 755 rc.local

0 篇笔记 写笔记

Centos7 nginx 环境搭建
安装nginx下载nginx安装包wget http://nginx.org/download/nginx-1.11.12.tar.gz2.解压并切换到解压目录tar -xvf nginx-1.11.12.tar.gzcd nginx-1.11.123.执行命令 ./configure如出现如下错误......
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!