新 Laravel (Homestead) 安装:502 Bad Gateway - *Refresh* - 网站显示正确

New Laravel (Homestead) installation: 502 Bad Gateway - *Refresh* - the website is displayed correctly

我尝试设置本地 Laravel 项目。所以我决定使用 Homestead vagrant box。 在我像 this Tutorial 一样安装完所有东西后,我期待在浏览器中看到结果:

第一个显示是 nginx 502 Bad Gateway Error。所以我尝试刷新它,然后显示默认的 Laravel 起始页面。然后我做了一些路由和 links 到我网站的一些子页面,每次我更改我的页面(通过 link 或输入 get 请求)我得到“502 Bad Gateway”,它在网站刷新。

我试过了:

遗憾的是,有时无法显示“502 Bad Gateway”。但是在我同事的电脑上(也是Windows10)一切都如你所料。

日志文件( /var/log/nginx ) 的站点:

2019/01/23 20:23:53 [error] 2532#2532: *1 recv() failed (104: Connection 
reset by peer) while reading response header from upstream, client: 
192.168.10.1, server: eatthis.test, request: "GET / HTTP/1.1", upstream: 
"fastcgi://unix:/var/run/php/php7.3-fpm.sock:", host: "eatthis.test"

2019/01/23 20:24:03 [error] 2532#2532: *1 recv() failed (104: Connection 
reset by peer) while reading response header from upstream, client: 
192.168.10.1, server: eatthis.test, request: "GET / HTTP/1.1", upstream: 
"fastcgi://unix:/var/run/php/php7.3-fpm.sock:", host: "eatthis.test"

和 /etc/nginx/sites-enabled/eatthis.test:

server {
listen 80;
listen 443 ssl http2;
server_name .eatthis.test;
root "/home/vagrant/code/Laravel/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/eatthis.test-error.log error;

sendfile off;

client_max_body_size 100m;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.3-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/eatthis.test.crt;
ssl_certificate_key /etc/nginx/ssl/eatthis.test.key;
}

我的Homestead.yaml:

---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox

authorize: c:/Users/XXXX/.ssh/id_rsa.pub

keys:
- c:/Users/XXXX/.ssh/id_rsa

folders:
- map: c:/www/code
  to: /home/vagrant/code

sites:
- map: eatthis.test
  to: /home/vagrant/code/Laravel/public

databases:
- homestead

# ports:
#     - send: 50000
#       to: 5000
#     - send: 7777
#       to: 777
#       protocol: udp

# blackfire:
#     - id: foo
#       token: bar
#       client-id: foo
#       client-token: bar

# zray:
#  If you've already freely registered Z-Ray, you can place the token here.
#     - email: foo@bar.com
#       token: foo
#  Don't forget to ensure that you have 'zray: "true"' for your site.

我的房东:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#       127.0.0.1       localhost
#       ::1             localhost
192.168.10.10 eatthis.test

我认为我的 PC 或我的 vagrant 有问题,但我不知道这可能是什么,因为文件在刷新后正在加载。

我希望有人能帮我解决这个问题。这种一直刷新的感觉好烦

尝试禁用 XDebug。这对我有用,但感觉有点老套。如果我想出更好的解决方案,我会更新这个。

"aliases" 中应该已经有一个 xoff 别名。所以 运行 xoff 在你的 vagrant box 中,然后重启 NGINX 和 PHP7.3-FPM。 (如果您没有或想要别名,请使用 sudo phpdismod -s cli xdebug 代替我提到的 "xoff")

步骤如下(记住这是通过宅基地盒完成的):

  1. xoff
  2. sudo service nginx restart
  3. sudo service php7.3-fpm restart
  4. 重新加载后重试并祈祷!

同样,我对这个解决方案还不满意。然而,这里是 how to disable XDbug in a more proper way 虽然我还没有测试过,所以如果你尝试的话,请告诉我结果如何。

希望这对你有用,我花了一整夜试图弄清楚这个问题,哈哈。现在是凌晨 5 点,我什至不确定我是否还在说英语。

Aaron Belz 的确切步骤对我不起作用,但遵循 link 对我有用。

这是 xdebug,对我来说也是不幸的。

sudo vim /etc/php/7.3/mods-available/xdebug.ini

并在所有行前加上 ; - 然后按照 Aaron 的说明进行操作:

sudo service nginx restart
sudo service php7.3-fpm restart

它奏效了。现在我担心是否需要 xdebug 来解决任何问题——在找到修复程序之前我将无法使用它。啊好吧,当我到达那里时穿过那座桥 :D

我还会注意到我在 Windows,我知道 Vagrant 有时会遇到问题,所以也许这与它有关。

同样的问题(nginx 上出现 502 错误)。我知道这是一个老问题,但最近又发生了,因为 laravel\homesteadrelease 分支中存在问题,其中尚未包含此更改: https://github.com/laravel/homestead/pull/1691/commits/78a573f62a9160e8d9c302667649089cf8a2435c

所以在我的例子中,运行 php 7.4 这两行解决了问题:

sudo systemctl enable php7.4-fpm
sudo service php7.4-fpm restart