dongpai6567
dongpai6567
2017-09-29 14:06
浏览 676
已采纳

Laravel on nginx显示403,但我的路径是正确的

I have a digitalocean droplet and I want to run a laravel project. I used this tutorial https://www.digitalocean.com/community/tutorials/how-to-deploy-a-laravel-application-with-nginx-on-ubuntu-16-04

The thing is that it displays a 403. I saw on other questions that they missed the public directory or they had the path wrong, but in my case I got a 403 when I have the public dir correct, and a 500 when I have it wrong.

My nginx error log says

2017/09/29 13:58:16 [error] 15176#15176: *2 directory index of "/var/www/laravel/public/" is forbidden

My nginx sites-available/my-site.com

server {
        listen 80;
        listen [::]:80;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/laravel/public;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name my-site.com www.my-site.com;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.php?$query_string;
        }

图片转代码服务由CSDN问答提供 功能建议

我有一个digitalocean droplet,我想运行一个laravel项目。 我使用了本教程 https://www.digitalocean.com/community/tutorials/how-to-deploy-a-laravel-application-with-nginx-on-ubuntu-16-04 \ n

事情是它显示403.我在其他问题上看到他们错过了公共目录或他们的路径错了,但在我的情况下,当我的公共目录正确时,我得到403 我错了500.

我的nginx错误日志说

  2017/09/29 13:58:16 [错误 ] 15176#15176:* 2目录索引“/ var / www / laravel / public /”被禁止
   
 
 

我的nginx sites-available / my-site。 com

  server {
 listen 80; 
 listen [::]:80; 
 
#SSL配置
#
#listen 443 ssl default_server;  
#listen [::]:443 ssl default_server; 
#
#注意:你应该为SSL traffi禁用gzip  c。
#请参阅:https://bugs.debian.org/773332
#
#阅读ssl_ciphers以确保安全配置。
#请参阅:https://bugs.debian.org/765782  
#
#由ssl-cert包生成的自签名证书
#不要在生产服务器中使用它们!
#
 #include snippets / snakeoil.conf; 
 
 root / var /  www / laravel / public; 
 
#如果您使用的是PHP,请将index.php添加到列表中\ index index index.html index.htm index.nginx-debian.html; 
 
 server_name my-site.com  www.my-site.com; 
 
 location / {
#首先尝试将请求作为文件提供,然后
#作为目录,然后再回到显示404. 
 try_files $ uri $ uri / /  index.php?$ query_string; 
} 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doudu8291
    doudu8291 2017-09-30 09:50
    已采纳

    The answer is right there in your nginx config. It is also shown in the tutorial you link to.

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;
    

    You have not added index.php.

    点赞 评论

相关推荐