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用戶下啓動