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条)

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害