nginx错误及解决

nginx错误及解决

常见的nginx错误及相应的解决方式。

root的配置

server域下直接配置了root,而/video想覆盖root,结果,都直接报404错误,大概的意思是无法找到文件。

server
    {
        listen 80 default_server reuseport;
        server_name _;
        index index.html index.htm index.php;
        root  /home/wwwroot/default;
        include enable-php.conf;

        location /video
        {
            root /mnt/data/mp4/;
            index index.html index.htm index.php;
        }
      .......

问题解决:

这是因为root设置的理解错误。浏览器访问 http://ip/video/index.html ,实际上对应的文件路径是,/mnt/data/mp4/video/index.html。而我,错误的以为是,/mnt/data/mp4/index.html,忘记了还要加浏览器上访问的路径video。因此,出404错了。

我猜测,如果不想设置location /video,应该能通过软连接,来访问到文件吧。果然,下面的命令设置,比直接配置nginx来的方便多了。

ln -s /mnt/data/mp4 /home/wwwroot/default/mp4;