mac open "/usr/usr local bin/var/run/nginx.pid" failed 是什么错误

网页设计教程与开发
提供各种常见网页效果
提供各种各样的设计教程
装扮QQ,让QQ变得更酷
设计参考,提高自升水平
学习服务器和操作系统
提供各种素材和工具
收藏学习资料
您现在的位置:&&>>&&>>&&>>&正文
重启nginx后丢失nginx.pid的解决方法
一,nginx的停止操作
停止操作是通过向nginx进程发送信号来实现的。步骤1:查询nginx主进程号。 代码如下:ps -ef | grep nginx
在进程列表里 面找master进程,它的编号就是主进程号了。
步骤2:发送信号
从容停止Nginx:kill -QUIT 主进程号快速停止Nginx:kill -TERM 主进程号强制停止Nginx:。 代码如下:pkill -9 nginx
另外, 若在nginx.conf配置了pid文件存放路径则该文件存放的就是Nginx主进程号,如果没指定则放在nginx的logs目录下。有了pid文 件,我们就不用先查询Nginx的主进程号,而直接向Nginx发送信号了,命令如下:。 代码如下:kill -信号类型 '/usr/nginx/logs/nginx.pid'
二,nginx的平滑重启
如果更改了配置就要重启Nginx,要先关闭Nginx再打开?不是的,可以向Nginx 发送信号,平滑重启。平滑重启命令:。 代码如下:kill -HUP 住进称号或进程号文件路径
或使用/usr/nginx/sbin/nginx -s reload注意,修改了配置文件后最好先检查一下修改过的配置文件是否正 确,以免重启后Nginx出现错误影响服务器稳定运行。判断Nginx配置是否正确命令如下:&
。 代码如下:nginx -t -c /usr/nginx/conf/nginx.conf或者/usr/nginx/sbin/nginx -t
三,nginx的平滑升级
如果服务器正在运行的Nginx要进行升级、添加或删除模块时,我们需 要停掉服务器并做相应修改,这样服务器就要在一段时间内停止服务,Nginx可以在不停机的情况下进行各种升级动作而不影响服务器运行。
若升级Nginx程序,先用新程序替换旧程序文件,编译安装的话新程序直接编译到Nginx安装目录中。
步骤2:执行命令
kill -USR2 旧版程序的主进程号或进程文件名
此时旧的Nginx主进程将会把自己的进程文件改名为.oldbin,然后执行新版 Nginx。新旧Nginx会同市运行,共同处理请求。这时要逐步停止旧版 Nginx,输入命令:
kill -WINCH 旧版主进程号
慢慢旧的工作进程就都会随着任务执行完毕而退出,新版的Nginx的工作进程会逐渐取代旧版 工作进程。可以决定使用新版还是恢复到旧版。
四,不重载配置启动新/旧工作进程
kill -HUP 旧/新版主进程号从容关闭旧/新进程kill -QUIT 旧/新主进程号如果此时报错,提示还有进程没有结束就用下面命令先关闭旧/新工作进程,再关闭主进程号:kill -TERM 旧/新工作进程号
这样下来,如果要恢复到旧版本,只需要上面的几个步 骤都是操作新版主进程号,如果要用新版本就上面的几个步骤都操作旧版主进程号就行了。
上面就是Nginx的一些基本的操作,希望以后Nginx能有更好的方法来处理这些操作, 最好是Nginx的命令而不是向Nginx进程发送系统信号。
在阿里云服务器上,进程性的 nginx -s stop后再次启动nginx -s reload ,总是会报错误nginx: [error] open() "/alidata/server/nginx/logs/nginx.pid" failed (2: No such file or directory)。原因:nginx进程杀死后pid丢失了,下一次再开启nginx -s reload时无法启动,重装可以解决问题,做不做,你决定吧,哈哈。
还是英文的解释比较专业:
issued a nginx -s stop and after that I got this error when trying to reload it.[error]: invalid PID number "" in "/var/run/nginx.pid"That /var/run/nginx/pid file is empty atm.What do I need to do to fix it?
nginx -s reload is only used to tell a running nginx process to reload its config. After a stop, you don't have a running nginx process to send a signal to. Just run nginx (possibly with a -c /path/to/config/file)
使用方法:。 代码如下:nginx -c /path/to/config/file//我的机器是这样:/alidata/server/nginx/sbin/nginx -c /alidata/server/nginx/conf/nginx.conf
转载请注明:破洛洛(谢谢合作)
上一篇文章: 下一篇文章:
网友评论:nginx不能正常访问,提示权限不足或文件不存在的错误!
今天通过yum安装了新的nginx(v1.6.2),修改了配置文件中的user,root,server_name,index,其他都是系统默认配置,浏览器访问时一直提示错误,权限不足或者文件不存在的错误(其中文件肯定是存在的)。
// 同网站根目录用户一致
root /tmp/
index index.php index.
无论设置nginx的user为root|admin|nginx|nobody,还是设置网站根目录的用户和权限(51||root|admin|nginx),都不行,一样错误!郁闷啊!!
根据(nginx -V)中prefix的设置(/usr/share/nginx),如果将网站根设置到(/usr/share/nginx)目录下面,可以访问html,jpg等类型的静态文件,但在访问php时(初始化thinkphp),提示”
愁到喽!!!
# nginx -V
nginx version: nginx/1.6.2
built by gcc 4.9.1
(Red Hat 4.9.1-11) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --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 --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module --with-http_perl_module --with-mail --with-mail_ssl_module --with-pcre --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'
# cat /etc/nginx/nginx.conf
# For more information on configuration, see:
* Official English Documentation: http://nginx.org/en/docs/
* Official Russian Documentation: http://nginx.org/ru/docs/
worker_processes
/var/log/nginx/error.
#error_log
/var/log/nginx/error.
#error_log
/var/log/nginx/error.
/run/nginx.
worker_connections
/etc/nginx/mime.
default_type
application/octet-
log_format
'$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log
/var/log/nginx/access.
#keepalive_timeout
keepalive_timeout
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.
80 default_
/usr/share/nginx/
/usr/share/nginx/thinkphp_3.2.3_
#charset koi8-r;
#access_log
/var/log/nginx/host.access.
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.
location / {
# redirect server error pages to the static page /40x.html
error_page
location = /40x.html {
# redirect server error pages to the static page /50x.html
error_page
500 502 503 504
location = /50x.html {
# cat /etc/nginx/conf.d/php-fpm.conf
# PHP-FPM FastCGI server
# network or unix domain socket configuration
upstream php-fpm {
server 127.0.0.1:9000;
# cat /etc/nginx/default.d/php.conf
# pass the PHP scripts to FastCGI server
# See conf.d/php-fpm.conf for socket configuration
index index.php index.
location ~ \.php$ {
try_files $uri =404;
fastcgi_intercept_
fastcgi_index
fastcgi_param
SCRIPT_FILENAME
$document_root$fastcgi_script_
fastcgi_pass
# uname -an
Linux minicooper 3.18.3-201.fc21.x86_64 #1 SMP Mon Jan 19 15:59:31 UTC
x86_64 x86_64 GNU/Linux
1、查看错误日记 /var/log/nginx/error. 以定位问题
2、检测nginx是否已使用了你配置的文件(可以故意出错测试)
3、确保目录/tmp/& 有执行权限
16:09:07 [error] 15278#0: *1 open() "/tmp/thinkphp_3.2.3_full/index.html" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /index.html HTTP/1.1", host: "localhost"
注:index.html文件是存在的。
16:09:37 [error] 15278#0: *1 open() "/tmp/thinkphp_3.2.3_full/asdfasdfsdaf.html" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /asdfasdfsdaf.html HTTP/1.1", host: "localhost"
注:asdfasdfsdaf.html文件是不存在的。
# systemctl restart nginx
Job for nginx.service failed. See "systemctl status nginx.service" and "journalctl -xe" for details.
# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx. disabled)
Active: failed (Result: exit-code) since 五
16:11:14 CST; 18s ago
Process: 15308 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
Process: 15275 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 15313 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
Main PID: 15277 (code=exited, status=0/SUCCESS)
3月 20 16:11:14 minicooper nginx[15313]: nginx: [emerg] invalid number of arguments in "user" directive in /etc/nginx/nginx.conf:6
3月 20 16:11:14 minicooper nginx[15313]: nginx: configuration file /etc/nginx/nginx.conf test failed
3月 20 16:11:14 minicooper systemd[1]: nginx.service: control process exited, code=exited status=1
3月 20 16:11:14 minicooper systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
3月 20 16:11:14 minicooper systemd[1]: Unit nginx.service entered failed state.
3月 20 16:11:14 minicooper systemd[1]: nginx.service failed.
注:这是将配置文件中user后面的分号去掉后的情况;
# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx. disabled)
Active: active (running) since 五
16:13:40 CST; 1s ago
Process: 15308 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
Process: 15332 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 15330 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Main PID: 15334 (nginx)
CGroup: /system.slice/nginx.service
├─15334 nginx: master process /usr/sbin/nginx
└─15335 nginx: worker process
3月 20 16:13:40 minicooper nginx[15330]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
3月 20 16:13:40 minicooper nginx[15330]: nginx: configuration file /etc/nginx/nginx.conf test is successful
注:这是正常情况;
网站根目录的执行权限全部调整过了,包括宿主,也是没有问题的。
问题解决了,原因在于:我使用的系统是fedora 21,系统默认的服务管理程序是systemctl,原来是这个有问题,如果在命令行中直接使用nginx启动服务,这一切正常,使用相同方式启动php-fpm后,php应用也正常。看来是分析问题的方向有问题了,只是一个服务管理程序而已,使用ps和netstat查看进程和端口,都正常,也就没有多想,正是害人不浅啊!!
systemctl enable nginx
systemctl restart nginx
systemctl enable php-fpm
systemctl restart php-fpm
之后就正常了。
可是还存在一个问题:
# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
# systemctl disable nginx
Removed symlink /etc/systemd/system/multi-user.target.wants/nginx.service.
这时候‘/etc/systemd/system/multi-user.target.wants/nginx.service’文件已经不存在了,实际查看也是不存在了,重启nginx后还是访问正常,看来不仅仅是创建link那么简单。
今天使用nginx又出现了权限不足的问题,检查所有配置,一切正常,按照上述方法检查systemctl status nginx,也都OK,无意中想到了selinux,就随手敲了关闭命令,没想到nginx居然正常了,检查一看没想到系统配置文件中还是打开的(记忆里好像是关掉的)。
上次出问题,除了权限不足还有文件不存在的错误,而今天是只是权限不足的问题,所以导致错误的源头应该两者都有,现在想想上次好像也使用了selinux的关闭命令,然后才是systemctl的问题,这次正好相反。
今天有时间看了一下,systemctl enable nginx这个命令是设置nginx自启动的。Nginx(7)
在Mac上用brew安装Nginx,然后修改Nginx配置文件,再重启时报出如下错误:
nginx: [error] invalid PID number && in &/usr/local/var/run/nginx/nginx.pid&
解决办法:
$ sudo nginx -c /usr/local/etc/nginx/nginx.conf
$ sudo nginx -s reload
&&相关文章推荐
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:166893次
积分:2518
积分:2518
排名:第13274名
原创:22篇
转载:432篇
评论:45条
(5)(11)(18)(9)(4)(6)(11)(4)(4)(5)(2)(18)(4)(8)(7)(6)(6)(4)(8)(7)(9)(10)(1)(5)(10)(7)(3)(9)(9)(3)(4)(5)(9)(30)(11)(11)(12)(43)(5)(1)(4)(7)(9)(21)(5)(9)(3)(14)(20)(18)“/usr/local/var/run/nginx.pid”failed - 简书
“/usr/local/var/run/nginx.pid”failed
解决方案:sudo nginx -c /usr/local/etc/nginx/nginx.confsudo nginx -s reload

我要回帖

更多关于 usr local 的文章

 

随机推荐