beyondcode / herd-community

89 stars 1 forks source link

[Bug]: Nginx unable to start #598

Closed AlexanderFromModus closed 7 months ago

AlexanderFromModus commented 7 months ago

Platform

Windows

Operating system version

Windows 11 22631.3296

System architecture

Windows

Herd Version

1.0.1

PHP Version

PHP 8.3

Bug description

Nginx unable to start after adding new site and assigning PHP 8.3, error log throws the following error:

2024/04/03 14:37:35 [emerg] 11880#37916: unexpected "-" in C:/Users/alexa/.config/herd/config/valet/Nginx/patient1.test.conf:27

Line 27:

        rewrite ^ "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Found</h2>
<hr><p>HTTP Error 404. The requested resource is not found.</p>
</BODY></HTML>" last;

Issue is 'fixed' when you replace the double quotes with single quotes as follows:

        rewrite ^ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Found</h2>
<hr><p>HTTP Error 404. The requested resource is not found.</p>
</BODY></HTML>' last;

Steps to reproduce

  1. Navigate to Sites
  2. Click '+' to add Site
  3. Select 'No starter kit'
  4. Click 'Next'
  5. Enter a project name, e.g. patient00
  6. Select a testing framework, e.g. Pest
  7. Select a Target Location, e.g. C:\Users\%user%\Herd
  8. Click 'Next'
  9. Wait for project to be created...
  10. Select PHP version 8.3 (it breaks here)
  11. Navigate back to Dashboard
  12. Stop all services
  13. Start all services

Nginx appears be unable to start

Relevant log output

2024/04/03 14:48:40 [emerg] 19864#23500: unexpected "-" in C:/Users/alexa/.config/herd/config/valet/Nginx/patient00.test.conf:17
sschlein commented 7 months ago

Can you please share the whole .conf file? The content of your line 27 does not make sense to me at all šŸ¤”

AlexanderFromModus commented 7 months ago

Sure @sschlein!

# ISOLATED_PHP_VERSION=8.3
server {
    listen 127.0.0.1:80;
    server_name patient00.test www.patient00.test *.patient00.test;
    #listen VALET_LOOPBACK:80; # valet loopback
    root /;
    charset utf-8;
    client_max_body_size 128M;

    location ~* /41c270e4-5535-4daa-b23e-c269744c2f45/([A-Z]+:)(.*) {
        internal;
        alias $1;
        try_files $2 $2/;
    }

    location / {
        rewrite ^ "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Found</h2>
<hr><p>HTTP Error 404. The requested resource is not found.</p>
</BODY></HTML>" last;
    }

    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 "C:/Users/alexa/.config/herd/Log/nginx-error.log";

    error_page 404 "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Found</h2>
<hr><p>HTTP Error 404. The requested resource is not found.</p>
</BODY></HTML>";

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass "$herd_sock_83";
        fastcgi_index "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Found</h2>
<hr><p>HTTP Error 404. The requested resource is not found.</p>
</BODY></HTML>";
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Not Found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Not Found</h2>
<hr><p>HTTP Error 404. The requested resource is not found.</p>
</BODY></HTML>";
        fastcgi_param HERD_HOME "C:/Users/alexa/.config/herd";
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location ~ /\.ht {
        deny all;
    }
}
sschlein commented 7 months ago

That's super weird - does that happen everytime when you isolate a site? It should be like this:

# ISOLATED_PHP_VERSION=8.3
server {
    listen 127.0.0.1:80;
    server_name patient01.test www.patient01.test *.patient01.test;
    #listen VALET_LOOPBACK:80; # valet loopback
    root /;
    charset utf-8;
    client_max_body_size 128M;

    location ~* /41c270e4-5535-4daa-b23e-c269744c2f45/([A-Z]+:)(.*) {
        internal;
        alias $1;
        try_files $2 $2/;
    }

    location / {
        rewrite ^ "C:/Program Files/herd/resources/app.asar.unpacked/resources/valet/server.php" last;
    }

    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 "C:/Users/seb/.config/herd/Log/nginx-error.log";

    error_page 404 "C:/Program Files/herd/resources/app.asar.unpacked/resources/valet/server.php";

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass "$herd_sock_83";
        fastcgi_index "C:/Program Files/herd/resources/app.asar.unpacked/resources/valet/server.php";
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME "C:/Program Files/herd/resources/app.asar.unpacked/resources/valet/server.php";
        fastcgi_param HERD_HOME "C:/Users/seb/.config/herd";
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

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

It looks like the internal API server isn't running and it can't get the right information.

AlexanderFromModus commented 7 months ago

Yup, everytime. Once I delete the .conf and restart the services the issue dissapears, and occurs again when assigning any PHP version.

Perhaps this error has something to do with it? The error is thrown on startup.

6hUXMTf

sschlein commented 7 months ago

It looks like something is already running on port 9001. Can you please open your Herd settings, go to PHP and set it to 9100 or so? After that, restarting could be a good idea.

Not sure what causes the root issue but this could track it down.

AlexanderFromModus commented 7 months ago

Afraid this did not fix the issue, even after changing to port 9100 it still states port 9001. Is there anything else I can do?

MktRVWyicN

mpociot commented 7 months ago

@AlexanderFromModus Can you verify that your %USERPROFILE%\.config\herd\config\config.json also has apiPort set to 9100? If not, please try changing the contents of the file manually and then restart Herd.

AlexanderFromModus commented 7 months ago

@mpociot I can confirm that apiPort was not set to 9100. When changing this manually, and restarting, the JavaScript error dissapears, so that's a good sign šŸ‘

The contents of my config.json is as follows:

{
    "apiPort": 9100,
    "autoUpdate": true,
    "openLastSiteInTinkerShortcut": "Control+Shift+Alt+T",
    "openLastSiteInTerminalShortcut": "CommandOrControl+Shift+C",
    "openSitesShortcut": "CommandOrControl+Shift+S",
    "openDumpsShortcut": "CommandOrControl+Alt+Shift+D",
    "clearDumpsShortcut": "CommandOrControl+Alt+Shift+C",
    "interceptDumpsShortcut": "CommandOrControl+Alt+Shift+I",
    "openMailsShortcut": "CommandOrControl+Alt+Shift+M",
    "openLogViewerShortcut": "CommandOrControl+Alt+Shift+L",
    "basePhpPort": 9100,
    "baseDebugAddition": 100,
    "smtpPort": 2525,
    "dumps": false,
    "mails": false,
    "setupCompleted": true,
    "activeVersion": "8.3"
}

Unfortunately, this does not fix the original issue concerning Nginx not starting. I tried restarting Herd, starting/stopping all services but the results are the same.

If it helps, feel free to contact me through Discord: capitalz

mpociot commented 7 months ago

Right, the problem still persists as your isolated site still has a faulty nginx config file. Please remove the nginx configuration file and re-isolate the site (if that's needed for your setup)

mpociot commented 7 months ago

@AlexanderFromModus Did this fix your problem? Then I can close this issue

AlexanderFromModus commented 7 months ago

@mpociot Where would this nginx config file be located? C:\Users\alexa\.config\herd\config\nginx\nginx.conf?

If so, deleting / removing the contents of this file results in a error.

mpociot commented 7 months ago

@AlexanderFromModus It's in C:\Users\alexa\.config\herd\config\valet\nginx