inx: [error] open() "/root/nginx/logs/nginx.pid" failed (2: No such file or directory)
时间: 2023-11-14 07:58:59 浏览: 142
这个错误是因为打开文件"/root/nginx/logs/nginx.pid"失败,原因是文件路径不存在。解决方法是检查是否有该路径,如果不存在则创建路径。你可以执行以下命令来启动nginx并指定配置文件路径:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
相关问题
nginx: [error] invalid PID number "/usr/local/nginx/logs/nginx.pid"
在这个错误信息中,"nginx: [error] invalid PID number "/usr/local/nginx/logs/nginx.pid"",它是由于nginx在加载配置文件时遇到了无效的进程ID号。而具体原因是由于nginx在重新读取配置文件时,检测到指定的进程ID文件"/usr/local/nginx/logs/nginx.pid"无效或不存在。解决方法是检查"/usr/local/nginx/logs/nginx.pid"文件是否存在,如果不存在,则需要手动指定nginx配置文件的路径来启动nginx,即使用命令"/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf"。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [nginx: [error] invalid PID number ; in /usr/local/nginx/logs/nginx.pid](https://blog.csdn.net/qq_25288617/article/details/124607984)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [解决 nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid](https://blog.csdn.net/cxs123678/article/details/80201412)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
linux如何把nginx写入/etc/init.d
要将Nginx写入/etc/init.d,可以按照以下步骤进行操作:
1. 创建一个新的文件,例如nginx,将其放在/etc/init.d/目录下。
2. 将以下脚本粘贴到该文件中:
```
#!/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: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/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/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
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 0
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
```
3. 修改脚本中的变量,例如nginx路径和NGINX_CONF_FILE等。
4. 保存并关闭文件,然后执行以下命令添加执行权限:
```
chmod +x /etc/init.d/nginx
```
5. 最后,可以使用以下命令来启动、停止、重启或检查Nginx的状态:
```
service nginx start
service nginx stop
service nginx restart
service nginx status
```
阅读全文