**1. 403 Forbidden** 尝试配置静态服务器,结果一直显示 403 Forbidden **首先要注意的是:一般不要把要访问的文件放在/root目录下,会有很多权限问题导致403错误** 下面是将文件放在了 /root/www/目录下,导致的权限问题解决办法! 配置文件如下: ```shell server { listen 80; server_name www.erica.com; location / { root /root/www/files/; autoindex on; autoindex_format html; autoindex_exact_size off; autoindex_localtime on; charset utf-8,gbk; } location /static/ { root /root/www/; index index.html; } } ``` 访问 www.erica.com 显示 403 Forbidden,查阅资料后发现这是**nginx权限**的问题 **解决办法:** 修改配置文件nginx.conf, 将 **user nginx** 改为**user root** 重启nginx : `nginx -s reload`   **2. 启动时报错** 使用sudo systemctl start nginx启动失败,查看日志 /var/log/nginx/error.log 发现如下错误 ```bash 2019/04/25 00:39:13 [emerg] 40863#40863: bind() to 0.0.0.0:80 failed (98: Address already in use) 2019/04/25 00:39:13 [emerg] 40863#40863: bind() to [::]:80 failed (98: Address already in use) 2019/04/25 00:39:13 [emerg] 40863#40863: bind() to 0.0.0.0:80 failed (98: Address already in use) 2019/04/25 00:39:13 [emerg] 40863#40863: bind() to [::]:80 failed (98: Address already in use) 2019/04/25 00:39:13 [emerg] 40863#40863: bind() to 0.0.0.0:80 failed (98: Address already in use) 2019/04/25 00:39:13 [emerg] 40863#40863: bind() to [::]:80 failed (98: Address already in use) 2019/04/25 00:39:13 [emerg] 40863#40863: still could not bind() 2019/04/25 00:53:31 [notice] 43072#43072: signal process started 2019/04/25 01:00:35 [emerg] 43751#43751: invalid number of arguments in "root" directive in /etc/nginx/conf.d/pdb.conf:9 2019/04/25 01:01:27 [emerg] 43881#43881: invalid number of arguments in "root" directive in /etc/nginx/conf.d/pdb.conf:9 ``` 看到日志薯片端口已经被占用,nginx默认启动80端口,使用 `sudo ss -tnlp`查看80端口被谁占用了  如上图所示,发现80端口被APache2占用,我选择停止Apache2 ```bash sudo systemctl stop Apache2 ``` 然后再启动nginx,OK,万事大吉,虽然很简单,冷静分析才是王道啊~ 最后修改:2019 年 08 月 21 日 11 : 16 AM © 著作权归作者所有