切换导航
简历
工具
演示
查询
导航菜单
服务端
30
前端
114
数据库
82
进阶开发
8
桌面程序
2
QA
15
软件使用
36
规范协议
5
操作系统
11
AI
0
复用资源
6
硬件
0
标签
Git
办公软件
开发工具
浏览器
工具箱
Web服务器
Gitee
Github
SVN
SQL Server / SSMS
Visual Studio
VS Code
nginx
微信
PS
SSH
Hyper
gitblit
Monorepo
VMware
IntelliJ IDEA
DataGrip
外部链接
.NET Core SDK和运行时安装包
淘宝 NPM 镜像
查询网
Tables Generator线上表格转换工具
引用cdn在线脚本和样式
首页
软件使用
Nginx 错误与解决方法
[TOC] ## 1. 问题一 ### 1.1. 问题描述 > [emerg]: getpwnam(“nginx”) failed ### 1.2. 分析原因 在nginx安装配置中是用nginx用户和nginx组来启动服务,但系统中没有nginx用户与nginx用户组 ### 1.3. 解决方法 + 创建对应nginx用户 ```Shell useradd -s /sbin/nologin -M nginx ``` + 重启nginx ```Shell /usr/local/nginx/sbin/nginx -s reload ``` <hr/> ## 2. 问题二 ### 2.1. 问题描述 >“nginx: [emerg] unknown directive "set_real_ip_from" in /usr/local/nginx/conf/nginx.conf:50 nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed” ### 2.2. 原因分析 nginx缺少了realip模块 ### 2.3. 解决办法 + 进入到nginx解压包目录 ```Shell cd /usr/local/nginx-1.15.12 ``` + 添加realip模块 + 注意nginx安装的目录,复制时记得修改成自己安装的目录 ```Shell ./configure --prefix=/usr/local/nginx --with-http_realip_module ``` + 重新编译和安装nginx ```Shell make && make install ``` + 重启nginx ```Shell /usr/local/nginx/sbin/nginx -s reload ``` <hr/> ## 3. 问题三 ### 3.1. 问题描述 >“nginx [error] open() nginx.pid failed No such file or directory” ### 3.2. 解决方法 #### 3.2.1. 方式一 进入nginx安装目录,查找是否有nginx.pid文件如果存在执行下面的命令 ```Shell # 启动nginx sudo nginx -c /usr/local/nginx/nginx.conf # 进入到nginx安装目录后重启nginx nginx -s reload ``` #### 3.2.2. 方式二 在方式一中没有找到nginx.pid文件,这时去修改nginx.conf中被注释 #pid logs/nginx.pid,将注释去除并修改路径为/usr/local/nginx/logs/nginx.pid ```Shell # 进入nginx目录 cd /usr/local/nginx/conf # 编辑配置文件去除注释的 #pid vim nginx.conf ``` 修改完nginx.conf配置文件后,在 /usr/local/nginx 目录下创建 logs 目录 ```Shell # 创建logs目录 mkdir /usr/local/nginx/logs # 重启nginx /usr/local/nginx/nginx -s reload ``` <hr/> ## 4. 问题四 ### 4.1. 问题描述 > nginx报错Failed to restart nginx.service Unit not found ### 4.2. 解决方法 + 在根目录下执行 ```Shell vim /etc/init.d/nginx ``` + 在打开的文件下插入下面的代码 ```Shell #!/bin/sh # nginx - this script starts and stops the nginx daemin # # 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" 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 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 esac ``` + 保存好上面的文件后进入/etc/init.d目录,然后执行下面的命令 ```Shell # 进入目录 cd /etc/init.d # 设置文件权限 chmod 755 /etc/init.d/nginx # 增加nginx服务 chkconfig --add nginx # 启动nginx服务 service nginx start ```
扫一扫手机看
点击排行
windows 文件资源管理器使用
Layui 弹窗open使用说明
SQL Server 中字符串函数使用
C# 使用QQ邮箱代理做邮件接收功能
SQL Server关于apply的两种形式cross apply 和 outer apply
ASP.NET MVC 模型的自定义验证
nvm安装及常用命令
SQL Server 中数据类型转换
SQL Server 中WITH AS短语的使用
IE浏览器下AJAX缓存问题导致数据不更新的解决办法
订阅号