Nginx上Laravel 5.5的路由设置应该放在哪里?

时间:2018-03-28 05:13:19

标签: php laravel nginx laravel-5 laravel-5.5

我是Nginx的新手,刚开始尝试使用WinNMP在Windows上尝试我已经成功安装并可以使用基本的PHP。然后我继续尝试Laravel 5.5。使用composer的安装似乎很成功,它给出了laravel错误页面:

enter image description here

我以前称这个网页的网址是http://localhost/mylaraveltest/public/

我检查了Laravel错误日志文件但没有错误消息。然后我检查了来自Nginx的错误消息并看到了:

2018/03/28 11:30:20 [warn] 8560#11828: *21 upstream server temporarily disabled while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /mylaraveltest/public/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9003", host: "localhost"
2018/03/28 11:30:20 [error] 8560#11828: *21 upstream timed out (10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /mylaraveltest/public/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9003", host: "localhost"

这似乎是与路由问题相关的问题。从official page开始,我似乎应该添加以下内容:

location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

问题是,它没有提到我应该把这一行放在哪里....而且似乎很明显我谷歌找到的所有指南只是专注于要添加的内容但是没有提到在哪里添加这一行。

我猜测并把它放在server的{​​{1}}括号内,但问题仍然存在。如果这是添加的错误位置,应该放在哪里?如果这是正确的地方,那还有什么可能导致问题?

1 个答案:

答案 0 :(得分:1)

您要查找的文件(通常)位于/etc/nginx/sites-enabled/site00.app

应包含类似的内容:

server {
    listen 80;
    listen 443 ssl http2;
    server_name .site00.app;
    root "/home/vagrant/sites/site00/site/public";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }



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

    access_log off;
    error_log  /var/log/nginx/site00.app-error.log error;

    sendfile off;

    client_max_body_size 100m;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
    }

    location ~ /\.ht {
        deny all;
    }

    ssl_certificate     /etc/nginx/ssl/site00.app.crt;
    ssl_certificate_key /etc/nginx/ssl/site00.app.key;
}

文件名和配置中site00.app的位置是应用程序的名称和tld。