php – 在nginx之后找不到Laravel路由

前端之家收集整理的这篇文章主要介绍了php – 在nginx之后找不到Laravel路由前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在我将ICG更改为Nginx之后,除索引页之外的所有路由都不起作用.

Laravel配置:

#/etc/Nginx/sites-enabled/laravel
server {
    listen 80;

    root /var/www/home;
    index index.PHP;

    server_name 192.168.178.71;

    access_log /var/www/home/storage/app/logs/laravel-Nginx-access.log;
    error_log  /var/www/home/storage/app/logs/laravel-Nginx-error.log error;


    location /home {
        root /home/public;
        try_files $uri $uri/ /index.PHP?$query_string;
    }

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt  { log_not_found off; access_log off; }


    # ERROR
    error_page 404 /index.PHP;


    # DENY HTACCESS
    location ~ /\.ht {
        deny all;
    }
}

默认配置:

# /etc/Nginx/sites-enabled/default
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www;

        # Add index.PHP to the list if you are using PHP
        index index.PHP index.html index.htm;

        server_name 192.168.178.71 localhost;

        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;

        autoindex on;

         # Remove trailing slash to please routing system.
          if (!-d $request_filename) {
            rewrite     ^/(.+)/$/$1 permanent;
        }


        }

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

        }

        location ~ /\.ht {
                deny all;
        }
}

我的Nginx配置

#/etc/Nginx/Nginx.conf
user www-data;
worker_processes 4;
pid /run/Nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
         disable_symlinks off;
        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/Nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3,ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/Nginx/access.log;
        error_log /var/log/Nginx/error.log;
       ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";



        ##
        # Virtual Host Configs
        ##

        include /etc/Nginx/conf.d/*.conf;
        include /etc/Nginx/sites-enabled/*;
}

我尝试了什么:

/var/www/home# (home folder is laravel folder)
sudo chown -R www-data:www-data *


/var/www/home# 
sudo chown -R root:root *

我也试着改变

 try_files $uri $uri/ /index.PHP?$query_string;
 try_files $uri $uri/ /index.PHP$is_args$args;
 try_files $uri $uri/ /index.PHP;


PHP artisan cache:clear  

谷歌的大多数问题我都读过,但没有什么可以帮助我.

我的PHPinfo – link

最佳答案
这是Laravel和Nginx的正确基本配置:

server {
    listen   80 default_server;

    root /var/www/laravel/public/;
    index index.PHP index.html index.htm;

    location / {
         try_files $uri $uri/ /index.PHP$is_args$args;
    }

    # pass the PHP scripts to FastCGI server listening on /var/run/PHP5-fpm.sock
    location ~ \.PHP${
            try_files $uri /index.PHP =404;
            fastcgi_pass unix:/var/run/PHP5-fpm.sock;
            fastcgi_index index.PHP;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
    }
}

编辑:
代替:

fastcgi_pass unix:/var/run/PHP5-fpm.sock;

截至2018年11月,当PHP 7.2出局时,它将是:

fastcgi_pass unix:/var/run/PHP7.2-fpm.sock;

猜你在找的Nginx相关文章