Centos7下安装nginx并且设置nginx开机启动

1.  nginx安装

下载nginx:

官方网站:

http://nginx.org/

使用的版本是1.8.0版本。

Nginx提供的源码。

1.1. 要求的安装环境

1、需要安装gcc的环境。yuminstall gcc-c++

2、第三方的开发包。

 PCRE(PerlCompatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。

yum install -y pcre pcre-devel

注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。

zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。

yum install -y zlib zlib-devel

       OpenSSL是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。

       nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。

yum install -y openssl openssl-devel

1.2. 安装步骤

第一步:把nginx的源码包上传到linux系统

第二步:解压缩

[root@localhost ~]# tar zxf nginx-1.8.0.tar.gz

cd nginx-1.8.0

第三步:使用configure命令创建一makeFile文件。

./configure \

--prefix=/usr/local/nginx \

--pid-path=/var/run/nginx/nginx.pid \

--lock-path=/var/lock/nginx.lock \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--with-http_gzip_static_module \

--http-client-body-temp-path=/var/temp/nginx/client\

--http-proxy-temp-path=/var/temp/nginx/proxy\

--http-fastcgi-temp-path=/var/temp/nginx/fastcgi\

--http-uwsgi-temp-path=/var/temp/nginx/uwsgi\

--http-scgi-temp-path=/var/temp/nginx/scgi

注意:启动nginx之前,上边将临时文件目录指定为/var/temp/nginx,需要在/var下创建tempnginx目录

[root@localhost sbin]# mkdir/var/temp/nginx/client -p

第四步:make

第五步:make install

1.3. 启动nginx

进入sbin目录

[root@localhost sbin]# ./nginx

关闭nginx:

[root@localhost sbin]# ./nginx -s stop

推荐使用:

[root@localhost sbin]# ./nginx -s quit

重启nginx:

1、先关闭后启动。

2、刷新配置文件:

[root@localhost sbin]# ./nginx -s reload

1.4. 访问nginx

默认是80端口。

注意:是否关闭防火墙。

1.5. 设置开机启动

  1. 在/root路径下新建一个nginxStart.sh,内容如下

#!/bin/bash
mkdir /var/run/nginx -p
/usr/local/nginx/sbin/nginx   #这里换成你自己的nginx可执行文件的路径

2. 在  /etc/rc.d/rc.local 文件末尾添加

 sh  /root/nginxStart.sh
南无阿弥陀佛!






猜你喜欢

转载自blog.csdn.net/u012150590/article/details/80139010
今日推荐