Daniel15 / simple-nuget-server

A very simple PHP NuGet server
MIT License
116 stars 43 forks source link

What does "Change "php" to the name of a PHP upstream in your Nginx config." mean? #30

Closed dougthor42 closed 6 years ago

dougthor42 commented 6 years ago

I'm having some trouble setting this up. I'm not familiar with nginx at all, sadly, so it's definitely on me.

In the readme, you have this line:

Change "php" to the name of a PHP upstream in your Nginx config. This can be regular PHP 5.4+ or HHVM.

Can you expand on that a bit? Which instance of "php" do I change? It shows up 15 times in the example nginx file.

If I ignore that change and attempt to start nginx, I get a no port in upstream "php" error:

$ sudo service nginx start
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
$ systemctl status nginx.service
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Mon 2018-04-16 16:04:48 PDT; 18s ago
  Process: 12968 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)

Apr 16 16:04:48 nuget systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 16 16:04:48 nuget nginx[12968]: nginx: [emerg] no port in upstream "php" in /etc/nginx/sites-enabled/nuget:25
Apr 16 16:04:48 nuget nginx[12968]: nginx: configuration file /etc/nginx/nginx.conf test failed
Apr 16 16:04:48 nuget systemd[1]: nginx.service: Control process exited, code=exited status=1
Apr 16 16:04:48 nuget systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Apr 16 16:04:48 nuget systemd[1]: nginx.service: Unit entered failed state.
Apr 16 16:04:48 nuget systemd[1]: nginx.service: Failed with result 'exit-code'.
Daniel15 commented 6 years ago

Sorry about that! I didn't document it well. Create a file at /etc/nginx/conf.d/php.conf with something like this in it:

upstream php {
    server unix:/run/php/php7.2-fpm.sock;
}

Assuming your PHP-FPM UNIX socket is at /run/php/php7.2-fpm.sock (this is configured in your PHP-FPM config, eg. /etc/php/7.2/fpm/pool.d/www.conf by default on Debian)

Configuring the upstream like this lets you do fastcgi_pass php in a website's Nginx config, rather than spreading an implementation detail (the exact path to the UNIX socket) throughout every website config on your server.

The alternative is to hard-code the path directly in the site's config, but this is usually not recommended:

fastcgi_pass unix:/run/php/php7.2-fpm.sock;
dougthor42 commented 6 years ago

Perfect, thanks! That's definitely good documentation (normally I'm an Apache user, but even then I only know the very basics and enough to harden the server...).