nginx解析不到laravel/public裡的index.php文件

WBOY
發布: 2016-08-20 09:04:02
原創
1994 人瀏覽過

我將/etc/nginx/sites-available/default裡面把root路徑改成裡/var/www/html/laravel/public了,但是運行結果是403,一開始以為是文件夾權限不夠,照著網上說都storage和vendor都權限都可以唸寫裡還是不行。 哪位大神幫我看看!
下面是我的nginx設定檔:

<code>server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # 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/html/laravel/public;

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

    server_name _;

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

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    
    #   With php7.0-cgi alone:
    #    fastcgi_pass 127.0.0.1:9000;
    #   With php7.0-fpm:
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#    listen 80;
#    listen [::]:80;
#
#    server_name example.com;
#
#    root /var/www/html/laravel/public;
#    index index.html;
#
#    location / {
#        try_files $uri $uri/ =404;
#    }
#}</code>
登入後複製
登入後複製

回覆內容:

我將/etc/nginx/sites-available/default裡面把root路徑改成裡/var/www/html/laravel/public了,但是運行結果是403,一開始以為是文件夾權限不夠,照著網上說都storage和vendor都權限都可以唸寫裡還是不行。 哪位大神幫我看看!
下面是我的nginx設定檔:

<code>server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # 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/html/laravel/public;

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

    server_name _;

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

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    
    #   With php7.0-cgi alone:
    #    fastcgi_pass 127.0.0.1:9000;
    #   With php7.0-fpm:
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#    listen 80;
#    listen [::]:80;
#
#    server_name example.com;
#
#    root /var/www/html/laravel/public;
#    index index.html;
#
#    location / {
#        try_files $uri $uri/ =404;
#    }
#}</code>
登入後複製
登入後複製

root下面一行的index後面加入一個index.php

問題找到了, 還是設定檔寫錯了

<code>root /var/www/html/laravel/public;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html ;  ------>这里面要加上index.php

    server_name _;------------>这里要把域名写成127.0.0.1或者local    但是后来我测试里下用下划线 貌似也是可以正常显示的</code>
登入後複製
相關標籤:
php
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!