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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探