Linux操作系统安装nginx

php中文网
发布: 2016-07-29 09:11:26
原创
1172人浏览过

下载

cd /user/local
wget http://nginx.org/download/nginx-1.8.0.tar.gz
登录后复制

安装依赖项
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
登录后复制

解压缩
tar -zxvf nginx-1.8.0.tar.gz
登录后复制

环境配置
cd nginx-1.8.0
./configure
登录后复制

安装
make && make install
登录后复制

启动
cd /usr/local/nginx
./nginx
登录后复制
查看
ps aux|grep nginx
登录后复制

关闭
./nginx -s stop
登录后复制

重启
./nginx -s reload
登录后复制

查看状态:
./nginx -t
登录后复制

如何开机自启动
cd /etc/init.d
touch nginx
登录后复制

新建一个文件后,编辑文件把如下内容粘贴入其中
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_c/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
登录后复制

赋予执行权限
<strong>chmod</strong> +x /etc/init.d/nginx
登录后复制

添加服务
chkconfig --add nginx
登录后复制

设置开机启动
chkconfig --level 35 nginx on
登录后复制

查看是否设置成功
chkconfig --list | grep nginx
登录后复制

Linux操作系统安装nginx

此状态下表面开机启动成功

家作
家作

淘宝推出的家装家居AI创意设计工具

家作 37
查看详情 家作

以上就介绍了Linux操作系统安装nginx,包括了chmod方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号