麒麟系统下的 nginx启动方法和自启动设置

一、手动启动方法

1、进入切换到root 权限(前提是使用root权限安装的 nginx,如没有使用root权限,则忽略此操作)

su root

输入root密码

进入nginx目录

cd /usr/local/nginx/sbin

启动nginx服务

./nginx

如不报错 则证明nginx启动成功

2、查看nginx是否启动成功

ps -ef |grep nginx

ps -C nginx -o pid

二、设置开机自启动

1、创建脚本

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
 

其中如下内容应更改成你的 nginx的安装目录

nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid

2、设置通过服务启动

chkconfig add /etc/init.d/nginx

service nginx start

service nginx stop

3、加入开机自启动

chkconfig nginx on

<think>好的,用户询问的是如何在麒麟系统启动Nginx。首先,我需要回忆一下之前提供的引用内容,看看是否有相关的启动方法。 根据引用[2][4],确实提到了启动Nginx方法。特别是引用[4]详细说明了需要切换到root权限,如果安装时使用了root权限的话。所以第一步应该确认用户是否以root权限安装的Nginx,如果是的话,需要先切换用户。然后,根据系统是否使用systemd,麒麟系统可能支持systemctl命令,所以用systemctl start nginx启动服务。同时,还要提到验证服务状态的命令,比如systemctl status nginx,这样用户能确认是否启动成功。 另外,引用[4]还提到了直接执行nginx二进制文件的方法,这适用于没有使用systemctl的情况。需要指导用户进入安装目录,通常是/usr/sbin/,然后运行nginx命令。这部分也要分步骤说明,避免用户找不到路径。 还有自启动设置的问题,用户可能不仅想手动启动,还希望开机自动运行。所以需要包括使用systemctl enable nginx设置开机启动。这也是引用[4]中提到的内容,应该正确引用。 另外,要注意权限问题,如果用户安装时没有使用root,可能需要用sudo或者提示权限不足的解决方法。不过引用里提到的是切换到root,所以可能默认用户已经用root安装了,但最好还是提醒一下权限问题。 最后,总结一下步骤:切换root、用systemctl启动、直接运行nginx、检查状态、设置。每个步骤都要清晰,用代码块标出命令,方便用户复制粘贴。同时,确保所有命令符合麒麟系统的环境,比如服务管理工具是否确实是systemctl,因为有些旧系统可能用service命令,但根据引用内容,这里应该用systemctl。 可能还需要提醒用户配置文件的位置,如果启动失败可能是配置错误,但用户的问题只涉及启动方法,所以暂时不需要深入。不过可以提到如果启动失败,可以检查配置文件,但根据引用,这可能属于后续问题。 确保回答结构清晰,分步骤说明,引用正确的来源,并在末尾生成相关问题。相关问题可以涉及安装方法、配置修改、故障排除等,根据已有引用内容来提出。</think>### 麒麟操作系统 Nginx 启动方法麒麟系统启动Nginx需要根据安装方式权限设置选择合适的方法,以下是具体步骤: #### 1. **切换root权限(如需要)** 如果安装时使用了root权限,需先切换到root用户: ```bash su root ``` 输入密码后执行后续操作[^4]。 #### 2. **通过systemctl启动** 麒麟系统通常支持`systemd`服务管理,使用以下命令启动Nginx: ```bash systemctl start nginx ``` 验证服务状态: ```bash systemctl status nginx # 显示"active (running)"表示成功 ``` #### 3. **直接运行Nginx二进制文件** 如果未通过包管理器安装,可进入Nginx安装目录(默认路径为`/usr/sbin/`)手动启动: ```bash cd /usr/sbin/ ./nginx ``` #### 4. **设置开机自启动** Nginx服务随系统启动: ```bash systemctl enable nginx ``` #### 5. **验证Nginx运行** 访问浏览器输入`http://localhost`或服务器IP地址,若显示Nginx欢迎页则表明启动成功。 --- ### 注意事项 - **配置文件路径**:默认配置文件位于`/etc/nginx/nginx.conf`,修改后需重服务生效[^2]。 - **权限问题**:若安装时未使用root权限,需通过`sudo`执行命令或调整目录权限[^4]。 - **日志查看**:错误日志位于`/var/log/nginx/error.log`,启动失败时可排查此处。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值