【问题标题】:Where should the routing settings for Laravel 5.5 on Nginx be put?Nginx 上 Laravel 5.5 的路由设置应该放在哪里?
【发布时间】:2018-03-28 13:32:57
【问题描述】:

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

我用来调用这个页面的url是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;
    }

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

我猜测了一下,放到nginx.confserver括号里面,但是问题依旧。如果这是错误的添加位置,应该放在哪里?如果这是正确的地方,那么还有什么可能导致问题?

【问题讨论】:

  • 你可以试试这个吗? try_files $uri $uri/ /index.php$is_args$args;
  • 首先,我添加的try_files相关设置是否正确?
  • 我猜 laravel 工作正常。你能显示你的路线吗
  • 我用这个try_files $uri $uri/ /index.php$is_args$args;
  • 我的意思是,我应该在哪里添加这一行?

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


【解决方案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。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-10
    • 2016-12-21
    相关资源
    最近更新 更多