阿里云CentOS 7下配置nginx环境
2017-10-15 20:07
495 查看
nginx是C语言开发,建议在linux上运行,本教程使用Centos6.5作为安装环境。
①gcc
安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc
yum install
gcc-c++
1
②PCRE
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yum install -y pcre pcre-devel
1
注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。
③zlib
zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
yum install -y zlib zlib-devel
1
④openssl
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -y openssl openssl-devel
wget -c http://nginx.org/download/nginx-1.12.0.tar.gz
tar -zxvf nginx-1.12.0.tar.gz
./configure
make
make install
whereis nginx
cd /usr/local/nginx/sbin/
./nginx
开机自启动nginx(非必要)
1、编写shell脚本
这里使用的是编写shell脚本的方式来处理
vi /etc/init.d/nginx (输入下面的代码)
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} =
"no" ] && exit
0
[ -x $nginxd ] ||
exit 0
# Start nginx daemons functions.
start() {
if [ -e
$nginx_pid ];then
echo
"nginx already running...."
exit
1
fi
echo -n $"Starting
$prog: "
daemon $nginxd -c
${nginx_config}
RETVAL=$?
echo
[ $RETVAL =
0 ] && touch /var/lock/subsys/nginx
return
$RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping
$prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL =
0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading
$prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1"
in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage:
$prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
:wq 保存并退出
2、设置文件的访问权限
chmod a+x /etc/init.d/nginx (a+x ==> all user can execute
所有用户可执行)
1
这样在控制台就很容易的操作nginx了:查看Nginx当前状态、启动Nginx、停止Nginx、重启Nginx…
如果修改了nginx的配置文件nginx.conf,也可以使用上面的命令重新加载新的配置文件并运行,可以将此命令加入到rc.local文件中,这样开机的时候nginx就默认启动了
3、加入到rc.local文件中
vi /etc/rc.local
1
2
加入一行 /etc/init.d/nginx start 保存并退出,下次重启会生效。
①gcc
安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc
yum install
gcc-c++
1
②PCRE
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yum install -y pcre pcre-devel
1
注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。
③zlib
zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
yum install -y zlib zlib-devel
1
④openssl
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -y openssl openssl-devel
wget -c http://nginx.org/download/nginx-1.12.0.tar.gz
tar -zxvf nginx-1.12.0.tar.gz
./configure
make
make install
whereis nginx
cd /usr/local/nginx/sbin/
./nginx
开机自启动nginx(非必要)
1、编写shell脚本
这里使用的是编写shell脚本的方式来处理
vi /etc/init.d/nginx (输入下面的代码)
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} =
"no" ] && exit
0
[ -x $nginxd ] ||
exit 0
# Start nginx daemons functions.
start() {
if [ -e
$nginx_pid ];then
echo
"nginx already running...."
exit
1
fi
echo -n $"Starting
$prog: "
daemon $nginxd -c
${nginx_config}
RETVAL=$?
echo
[ $RETVAL =
0 ] && touch /var/lock/subsys/nginx
return
$RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping
$prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL =
0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading
$prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1"
in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage:
$prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
:wq 保存并退出
2、设置文件的访问权限
chmod a+x /etc/init.d/nginx (a+x ==> all user can execute
所有用户可执行)
1
这样在控制台就很容易的操作nginx了:查看Nginx当前状态、启动Nginx、停止Nginx、重启Nginx…
如果修改了nginx的配置文件nginx.conf,也可以使用上面的命令重新加载新的配置文件并运行,可以将此命令加入到rc.local文件中,这样开机的时候nginx就默认启动了
3、加入到rc.local文件中
vi /etc/rc.local
1
2
加入一行 /etc/init.d/nginx start 保存并退出,下次重启会生效。
相关文章推荐
- Centos7下编译安装配置Nginx+PHP+MySql环境
- 在阿里云服务器上配置CentOS+Nginx+Python+Flask环境
- 阿里云CENTOS系统安装PHP+MYSQL+NGINX环境配置
- Centos7下配置PHP + MySQL + Nginx开发环境
- 在阿里云服务器上配置CentOS+Nginx+Python+Flask环境
- 阿里云服务器配置开发环境第七章:Centos7.3安装nginx以及环境配置
- 阿里云centos环境之nginx实站配置<十二>
- 阿里云 ecs 的 centOS7.2 环境利用 xshell 配置 ftp 登录的用户账号和密码
- 常用服务器软件nginx、jvm、centOS网络环境等配置
- 在阿里云 CentOS 服务器(ECS)上搭建 nginx + mysql + php-fpm 环境
- 在阿里云centOS上搭建 nginx tomcat mysql 环境
- Django+uWSGI+nginx阿里云服务器部署-centos6.8环境
- CentOS环境配置nginx-第一篇
- 阿里云的CentOS系统配置java web环境
- 阿里云CentOS 7下配置及使用mysql
- 生成环境下的Tomcat 8.0.36 在CentOS7下安装和配置apr
- 阿里云服务器ECS centos7.2搭建nginx环境以及负载均衡
- 阿里云Centos配置LNMP环境
- 在阿里云的CentOS环境中安装配置MySQL的教程_Mysql
- centos7下nginx自动启动配置