Nginx安装及配置的方法
发布时间 - 2023-05-20 00:00:00 点击率:次环境准备
1. 操作系统
centos 6.4 x86_64
2.软件版本
nginx 1.4.2
3.实验拓扑
4.安装yum源
[root@nginx ~]# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm [root@web1 ~]# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm [root@web2 ~]# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
5.各节点时间同步
[root@nginx ~]# ntpdate 202.120.2.101 [root@web1 ~]# ntpdate 202.120.2.101 [root@web2 ~]# ntpdate 202.120.2.101
6.关闭防火墙与selinux
[root@nginx ~]# service iptables stop [root@nginx ~]# chkconfig iptables off [root@nginx ~]# getenforce disabled [root@web1 ~]# service iptables stop [root@web1 ~]# chkconfig iptables off [root@web1 ~]# getenforce disabled [root@web2 ~]# service iptables stop [root@web2 ~]# chkconfig iptables off [root@web2 ~]# getenforce disabled
安装nginx
1.解压
[root@nginx src]# tar xf nginx-1.4.2.tar.gz
2.新建nginx用户与组
[root@nginx src]# groupadd -g 108 -r nginx [root@nginx src]# useradd -u 108 -r -g 108 nginx [root@nginx src]# id nginx uid=108(nginx) gid=108(nginx) 组=108(nginx)
3.准备编译配置文件
[root@nginx src]# yum install -y pcre-devel openssl-devel [root@nginx nginx-1.4.2]# ./configure --prefix=/usr --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --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 --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --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
4.编译并安装
[root@nginx nginx-1.4.2]# make && make install
5.为nginx提供sysv init脚本
[root@nginx ~]# cat /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: nginx is an http(s) server, http(s) reverse \
# proxy and imap/pop3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# source function library.
. /etc/rc.d/init.d/functions
# source networking configuration.
. /etc/sysconfig/network
# check that networking is up.
[ "$networking" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
nginx_conf_file="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -v 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
options=`$nginx -v 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -r $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $nginx_conf_file ] || exit 6
make_dirs
echo -n $"starting $prog: "
daemon $nginx -c $nginx_conf_file
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"stopping $prog: "
killproc $prog -quit
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"reloading $prog: "
killproc $nginx -hup
retval=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $nginx_conf_file
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac6.为此脚本赋予执行权限
[root@nginx ~]# chmod +x /etc/init.d/nginx
7.添加至服务管理列表,并让其开机自动启动
[root@nginx ~]# chkconfig --add nginx [root@nginx ~]# chkconfig nginx on [root@nginx ~]# chkconfig nginx --list nginx 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
8.启动nginx
[root@nginx ~]# service nginx start 正在启动 nginx: [确定]
9.查看一下端口
[root@nginx ~]# netstat -ntlp | grep :80 tcp 0 0 0.0.0.0:80 0.0.0.0:* listen 3889/nginx
10.测试一下
# nginx
# centos
# 服务管理
# 让其
# 配置文件
# 并安装
# 测试一下
# 自动启动
# 操作系统
# 软件版本
# conf
# path
相关栏目:
【
网站优化151355 】
【
网络推广146373 】
【
网络技术251813 】
【
AI营销90571 】
相关推荐:
深圳网站制作培训,深圳哪些招聘网站比较好?
怎么用AI帮你为初创公司进行市场定位分析?
JavaScript如何操作视频_媒体API怎么控制播放
详解Android中Activity的四大启动模式实验简述
如何在自有机房高效搭建专业网站?
手机软键盘弹出时影响布局的解决方法
如何快速选择适合个人网站的云服务器配置?
php结合redis实现高并发下的抢购、秒杀功能的实例
javascript基于原型链的继承及call和apply函数用法分析
Java类加载基本过程详细介绍
Linux后台任务运行方法_nohup与&使用技巧【技巧】
Laravel如何实现数据导出到CSV文件_Laravel原生流式输出大数据量CSV【方案】
如何在宝塔面板中修改默认建站目录?
js实现获取鼠标当前的位置
Laravel怎么定时执行任务_Laravel任务调度器Schedule配置与Cron设置【教程】
惠州网站建设制作推广,惠州市华视达文化传媒有限公司怎么样?
深圳网站制作的公司有哪些,dido官方网站?
如何彻底卸载建站之星软件?
如何快速搭建FTP站点实现文件共享?
如何用低价快速搭建高质量网站?
东莞市网站制作公司有哪些,东莞找工作用什么网站好?
HTML 中动态设置元素 name 属性的正确语法详解
如何确保西部建站助手FTP传输的安全性?
香港服务器租用每月最低只需15元?
Laravel怎么实现支付功能_Laravel集成支付宝微信支付
Laravel Seeder怎么填充数据_Laravel数据库填充器的使用方法与技巧
湖南网站制作公司,湖南上善若水科技有限公司做什么的?
Laravel中的withCount方法怎么高效统计关联模型数量
Laravel如何实现登录错误次数限制_Laravel自带LoginThrottles限流配置【方法】
如何在万网ECS上快速搭建专属网站?
Python文件异常处理策略_健壮性说明【指导】
Laravel如何与Pusher实现实时通信?(WebSocket示例)
Laravel Eloquent访问器与修改器是什么_Laravel Accessors & Mutators数据处理技巧
海南网站制作公司有哪些,海口网是哪家的?
Laravel怎么实现前端Toast弹窗提示_Laravel Session闪存数据Flash传递给前端【方法】
Laravel如何为API生成Swagger或OpenAPI文档
如何在浏览器中启用Flash_2025年继续使用Flash Player的方法【过时】
JavaScript实现Fly Bird小游戏
佐糖AI抠图怎样调整抠图精度_佐糖AI精度调整与放大细化操作【攻略】
简单实现jsp分页
如何在Tomcat中配置并部署网站项目?
零基础网站服务器架设实战:轻量应用与域名解析配置指南
Laravel怎么使用Collection集合方法_Laravel数组操作高级函数pluck与map【手册】
矢量图网站制作软件,用千图网的一张矢量图做公司app首页,该网站并未说明版权等问题,这样做算不算侵权?应该如何解决?
laravel怎么实现图片的压缩和裁剪_laravel图片压缩与裁剪方法
如何选择PHP开源工具快速搭建网站?
Android使用GridView实现日历的简单功能
Laravel怎么集成Vue.js_Laravel Mix配置Vue开发环境
如何用PHP工具快速搭建高效网站?
googleplay官方入口在哪里_Google Play官方商店快速入口指南


用 3:启用 4:启用 5:启用 6:关闭