Search code examples
nginxwebpackvagrantwebpack-dev-serverhomestead

Homestead - Nginx 502 error with Vue webpack server


I am using Homestead ( tag: v10.3.1) locally (for Symfony 4.4 API development) next to Vue application (which I run locally by npm run serve ) on localhost:8080 which use those Symfony API from Homestead. I am noticed that when I have turning on the Vue server (to be precise it is a webpack server) the Vagrant machine after some time returns me 502 error status code (from vagrant nginx).

I've been tried to change default webpack server port to 8082 but it not help. Problem still occur.

When I disable webpack server (for Vue) and do vagrant reload --provision - the nginx return to live.

I've made an request for this problem on official Laravel slack but I didn't get any request for this problem.

nginx error logs for domain:

2020/03/12 11:31:04 [error] 1484#1484: *1 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.10.1, server: app-admin.local.pl, request: "POST /api/login HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "app-admin.local.pl", referrer: "http://localhost:8080/"

I am working on Ubuntu 18.04 system.

Homestead.yml:

---
ip: "192.168.10.10"
memory: 4096
cpus: 4
provider: virtualbox

authorize: ~/.ssh/id_rsa.pub

keys:
    - ~/.ssh/id_rsa

folders:
    - map: ~/Dev/kiratikadminconsole-apiplatform
      to: /home/vagrant/kiratikadminconsole-apiplatform

sites:
    - map: app-admin.local.pl
      to: /home/vagrant/kiratikadminconsole-apiplatform/public
      type: symfony4

databases:
    - router_db

features:
    - mariadb: false
    - ohmyzsh: false
    - webdriver: false

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

Site nginx config file: (inside vagrant)

server {
    listen 80;
    listen 443 ssl http2;
    server_name app-admin.local.pl;
    root "/home/vagrant/kiratikadminconsole-apiplatform/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/app-admin.local.pl-ssl-error.log error;

    sendfile off;

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


        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }

    location ~ /\.ht {
        deny all;
    }



    ssl_certificate     /etc/nginx/ssl/app-admin.local.pl.crt;
    ssl_certificate_key /etc/nginx/ssl/app-admin.local.pl.key;
}

Does anybody noticed same issue here or similar problem or maybe someone can help me with this problem?

If you need more information I will provide it.


Solution

  • I see that no one has same problem or it's not connectect directly with Homestead.

    I worked on Homestead with the php newest version 7.4. My last chance was to change it to lower version and I changed it to php 7.1. Issue with 502 error dissapear.

    So if you will have similar problem it can be workaroud (if you don't need the specific PHP version and you can downgrade it).

    I don't know what is the "root" problem.