dongzhuoxie1244 2015-08-28 04:40
浏览 84
已采纳

nginx提供404页

EDIT: Based on @Devons advice I ran the following commands with no errors (found in this post):

$ sudo find /var/public/www -type d -exec chmod 755 {} +

$ sudo find /var/public/www -type f -exec chmod 644 {} +

But when I list the files inside www the permissions still look wrong. What am I doing wrong? Thanks!

drwxrwx--- 1 root vboxsf   4096 Aug 28 12:45 app
-rwxrwx--- 1 root vboxsf   1646 Aug 28 12:45 artisan
drwxrwx--- 1 root vboxsf      0 Aug 28 12:45 bootstrap
-rwxrwx--- 1 root vboxsf   1201 Aug 28 12:45 composer.json
-rwxrwx--- 1 root vboxsf 105046 Aug 28 12:55 composer.lock
drwxrwx--- 1 root vboxsf   4096 Aug 28 12:45 config
drwxrwx--- 1 root vboxsf      0 Aug 28 12:45 database
-rwxrwx--- 1 root vboxsf    503 Aug 28 12:45 gulpfile.js
-rwxrwx--- 1 root vboxsf    159 Aug 28 12:45 package.json
-rwxrwx--- 1 root vboxsf     87 Aug 28 12:45 phpspec.yml
-rwxrwx--- 1 root vboxsf    899 Aug 28 12:45 phpunit.xml
drwxrwx--- 1 root vboxsf      0 Aug 28 12:45 public
-rwxrwx--- 1 root vboxsf   1928 Aug 28 12:45 readme.md
drwxrwx--- 1 root vboxsf      0 Aug 28 12:45 resources
-rwxrwx--- 1 root vboxsf    567 Aug 28 12:45 server.php
drwxrwx--- 1 root vboxsf      0 Aug 28 12:45 storage
drwxrwx--- 1 root vboxsf      0 Aug 28 12:45 tests
drwxrwx--- 1 root vboxsf   4096 Aug 28 12:56 vendor

This is my first time with nginx and cannot get laravel welcome page to show. I am using ubuntu 14.04 and VBox 5.

I have my server configured in /var/nginx/sites-enabled/default as

server {
    listen 80 default_server;
    charset utf-8;
    server_name doimain.app www.domain.app;

    root /var/www/public;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Inside /var/www/public I can list the laravel public folder files

$ ls -l /var/www/public
total 3
-rwxrwx--- 1 root vboxsf    0 Aug 28 12:45 favicon.ico
-rwxrwx--- 1 root vboxsf 1786 Aug 28 12:45 index.php
-rwxrwx--- 1 root vboxsf   24 Aug 28 12:45 robots.txt

But I get 404 when I go to domain.app. The nginx error log shows:

2015/08/28 14:29:35 [crit] 1487#0: *14 stat() "/var/www/public/index.php" failed (13: Permission denied), client: 10.0.0.18, server: domain.app, request: "GET / HTTP/1.1", host: "domain.app"

I have tried without success the following:

Ensure www-data owns the folder structure /var/www

$ sudo chown www-data:www-data /var/www

Changed access rights to /var/www

$ sudo chmod -R 0755 /var/www

Thanks!

  • 写回答

2条回答 默认 最新

  • dpwbc42604 2015-08-28 04:44
    关注

    The public directory is owned by root and is not readable to others. You either need to change the ownership to www-data or chmod all of the folder and files. The folder should be 0755 and files be 0644 for most configurations. You can leave it how you have it if the files are owned by the same user running nginx and php (I assume www-data).

    Changing the ownership of /var/www by itself does nothing, you have to change all the folders and files in the web directory.

    You can chmod and chown recursively with the -R flag.

    chown -R www-data:www-data /var/www/public
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含