1.1 Nginx启动报错

        当前系统:

[oldboy@nginx-proxy nginx-1.10.3]$ cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

        检查语法报错:

[oldboy@nginx-proxy nginx-1.10.3]$ pwd
/opt/nginx-1.10.3
[oldboy@nginx-proxy nginx-1.10.3]$ sbin/nginx -t
nginx: [alert] could not open error log file: open() "/opt/nginx-1.10.3//logs/error.log" failed (13: Permission denied)
nginx: the configuration file /opt/nginx-1.10.3//conf/nginx.conf syntax is ok
2019/01/06 21:47:53 [emerg] 22206#0: open() "/opt/nginx-1.10.3//logs/nginx.pid" failed (13: Permission denied)
nginx: configuration file /opt/nginx-1.10.3//conf/nginx.conf test failed

        启动Nginx报错:

[oldboy@nginx-proxy nginx-1.10.3]$ sbin/nginx
nginx: [alert] could not open error log file: open() "/opt/nginx-1.10.3//logs/error.log" failed (13: Permission denied)
2019/01/06 22:16:38 [emerg] 22355#0: open() "/opt/nginx-1.10.3//logs/access.log" failed (13: Permission denied)

报错原因:

当前用户没有对该位置写入权限。

解决办法:

方法1):使用sudo命令用root权限启动

#查看当前用户有哪些root权限
[oldboy@nginx-proxy nginx-1.10.3]$ sudo -l
[sudo] password for oldboy:
Matching Defaults entries for oldboy on this host:
    requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR
    USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC
    LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin
 
User oldboy may run the following commands on this host:
(ALL) /opt/nginx/sbin/nginx, (ALL) /bin/netstat, (ALL) /sbin/lsof
#用sudo命令检查语法及启动
[oldboy@nginx-proxy nginx-1.10.3]$ sudo sbin/nginx -t
nginx: the configuration file /opt/nginx-1.10.3//conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx-1.10.3//conf/nginx.conf test is successful
[oldboy@nginx-proxy nginx-1.10.3]$ sudo sbin/nginx -s reload
[oldboy@nginx-proxy nginx-1.10.3]$ sudo lsof -i :80
COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   15641  root    6u  IPv4  31669      0t0  TCP *:http (LISTEN)
nginx   22344 nginx    6u  IPv4  31669      0t0  TCP *:http (LISTEN)
[oldboy@nginx-proxy nginx-1.10.3]$ sudo netstat -lnpt|grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      15641/nginx: master

提示:如果没有启动权限,则需要管理员赋予权限。

方法2):进入到root用户下启动