linux下安装nginx服务器
2017-12-31 14:01
399 查看
1.安装环境
本次使用rpm,也可以使用源码进行安装
7.创建日志文件logs(/usr/local/nginx目录下)
mkdir logs
8.查看nginx是否安装成功
cd /usr/local/nginx/sbin
./nginx -t
如果显示如下内容代表安装成功
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
9.启动nginx(未配置系统启动nginx下启动方法)
cd /usr/local/nginx/sbin
./nginx 启动nginx
./nginx -s stop 关闭nginx
./nginx -s quit 退出
./nginx -s reload 重启reload
10.给防火墙添加端口
firewall-cmd --zone=public --add-port=80/tcp --permanen 添加端口
firewall-cmd --reload 重启防火墙
80端口无需在阿里服务器进行配置端口,默认已开通
浏览器中输入ip地址就可以显示出如下内容:说明已经安装好了
11.添加系统环境变量
vim /etc/profile
加入如下内容:
PATH=$PATH:/usr/local/nginx/sbin
export PATH
保存关闭后运行 source /etc/profile 环境变量并生效
12.新增系统服务
cd /etc/rc.d/init.d
touch nginx
vi nginx
#!/bin/bash
# chkconfig: 2345 10 90
# description: nginx
. /etc/rc.d/init.d/functions
function show_usage(){
usage="Usage: `basename $0` [ start|stop|restart|reload ]"
echo $usage
exit
}
base_dir=/usr/local/nginx/
[[ $# != 1 ]] && show_usage
nginx=${base_dir}sbin/nginx
case $1 in
start)
[[ `netstat -ntlup|grep nginx|wc -l` > 0 ]] && failure && echo "Nginx is Running!" && exit
echo "Starting Nginx..."
$nginx
([ $? -eq 0 ] && success && echo "Nginx starts successfully!") || (failure && echo "Failed start nginx")
;;
stop)
[[ `netstat -ntlup|grep nginx|wc -l` == 0 ]] && failure && echo "Nginx is NOT running!" && exit
echo "Stopping Nginx..."
$nginx -s stop
([ $? -eq 0 ] && success && echo "Nginx stops successfully!") || (failure && echo "Failed stop nginx!")
;;
restart)
if [[ `netstat -ntlup|grep nginx|wc -l` == 0 ]]; then
echo "Starting Nginx..."
$nginx
[ $? -eq 0 ] && success && echo "Nginx starts successfully!"
else
echo "Stopping Nginx..."
$nginx -s stop
([ $? -eq 0 ] && success && echo "Nginx stops successfully!") || (failure && echo "Failed stop nginx!")
echo "Starting Nginx..."
$nginx
([ $? -eq 0 ] && success && echo "Nginx starts successfully!") || (failure && echo "Failed start nginx")
fi
;;
reload)
[[ `netstat -ntlup|grep nginx|wc -l` == 0 ]] && failure && echo "Nginx is NOT Running!" && exit
$nginx -s reload
[ $? -eq 0 ] && success && echo "Nginx reloads successfully!"
;;
*)
show_usage
;;
esac
chkconfig --add nginx
chkconfig nginx on
13.系统服务
service nginx start 启动
service nginx stop 关闭
service nginx restart 重启
本次使用rpm,也可以使用源码进行安装
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
yum install gcc-c++
2.下载nginx(/usr/local目录下)
wget https://nginx.org/download/nginx-1.11.11.tar.gz tar完整的,否则安装失败
3.解压(/usr/local目录下)
tar -zxvf nginx-1.11.11.tar.gz
4.重命名(/usr/local目录下)
rename nginx-1.11.11 nginx nginx-1.11.11
5.配置(/usr/local/nginx目录下)
./configure
6.安装(/usr/local/nginx目录下)
make
7.创建日志文件logs(/usr/local/nginx目录下)
mkdir logs
8.查看nginx是否安装成功
cd /usr/local/nginx/sbin
./nginx -t
如果显示如下内容代表安装成功
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
9.启动nginx(未配置系统启动nginx下启动方法)
cd /usr/local/nginx/sbin
./nginx 启动nginx
./nginx -s stop 关闭nginx
./nginx -s quit 退出
./nginx -s reload 重启reload
10.给防火墙添加端口
firewall-cmd --zone=public --add-port=80/tcp --permanen 添加端口
firewall-cmd --reload 重启防火墙
80端口无需在阿里服务器进行配置端口,默认已开通
浏览器中输入ip地址就可以显示出如下内容:说明已经安装好了
11.添加系统环境变量
vim /etc/profile
加入如下内容:
PATH=$PATH:/usr/local/nginx/sbin
export PATH
保存关闭后运行 source /etc/profile 环境变量并生效
12.新增系统服务
cd /etc/rc.d/init.d
touch nginx
vi nginx
#!/bin/bash
# chkconfig: 2345 10 90
# description: nginx
. /etc/rc.d/init.d/functions
function show_usage(){
usage="Usage: `basename $0` [ start|stop|restart|reload ]"
echo $usage
exit
}
base_dir=/usr/local/nginx/
[[ $# != 1 ]] && show_usage
nginx=${base_dir}sbin/nginx
case $1 in
start)
[[ `netstat -ntlup|grep nginx|wc -l` > 0 ]] && failure && echo "Nginx is Running!" && exit
echo "Starting Nginx..."
$nginx
([ $? -eq 0 ] && success && echo "Nginx starts successfully!") || (failure && echo "Failed start nginx")
;;
stop)
[[ `netstat -ntlup|grep nginx|wc -l` == 0 ]] && failure && echo "Nginx is NOT running!" && exit
echo "Stopping Nginx..."
$nginx -s stop
([ $? -eq 0 ] && success && echo "Nginx stops successfully!") || (failure && echo "Failed stop nginx!")
;;
restart)
if [[ `netstat -ntlup|grep nginx|wc -l` == 0 ]]; then
echo "Starting Nginx..."
$nginx
[ $? -eq 0 ] && success && echo "Nginx starts successfully!"
else
echo "Stopping Nginx..."
$nginx -s stop
([ $? -eq 0 ] && success && echo "Nginx stops successfully!") || (failure && echo "Failed stop nginx!")
echo "Starting Nginx..."
$nginx
([ $? -eq 0 ] && success && echo "Nginx starts successfully!") || (failure && echo "Failed start nginx")
fi
;;
reload)
[[ `netstat -ntlup|grep nginx|wc -l` == 0 ]] && failure && echo "Nginx is NOT Running!" && exit
$nginx -s reload
[ $? -eq 0 ] && success && echo "Nginx reloads successfully!"
;;
*)
show_usage
;;
esac
chkconfig --add nginx
chkconfig nginx on
13.系统服务
service nginx start 启动
service nginx stop 关闭
service nginx restart 重启
相关文章推荐
- Linux下Tomcat+Nginx服务器环境安装配置的简明教程
- Linux:安装nginx,搭建图片服务器
- linux下平滑升级nginx,nginx安装第三方模块echo-nginx-module——linux安装配置web服务器7
- Linux下安装Nginx服务器
- LNMP一键安装Linux系统下Nginx+MySQL+PHP这种网站服务器架构
- 虚拟机Linux系统安装nginx服务器并启动的步骤
- nginx在linux系统下的安装部署,以及反向代理https请求协议,ssl证书的生成,负载均衡tomcat服务器!
- linux下php源码安装(nginx服务器篇)
- Linux+Nginx+Mysql+PHP服务器运行环境安装
- Linux\CentOS系统下的服务器搭建,下载编译环境,安装vsFtpd、nginx、MySQL、JDK、Tomcat、PHP
- linux-搭建web服务器系列--安装搭建nginx(五)
- 010 Linux 下通过yum、apt、dnf方式安装和配置Nginx服务器
- Linux下安装Nginx服务器
- Linux 系统(ubuntu和CentOS)nginx服务器和php安装
- linux 源码包安装LNMP(linux+nginx+mysql+php)服务器环境
- nginx反向代理的服务器安装及域名解析配置(Linux)
- linux系统安装nginx服务器
- 【Linux进阶】CentOS安装Nginx服务器
- Linux服务器架设篇之(二)–源码安装Web服务器Nginx