dsavell / docker-grav

Docker Container for GRAV CMS
MIT License
42 stars 18 forks source link

Nginx/PHP server name #20

Closed hughbris closed 1 year ago

hughbris commented 4 years ago

This seems like a general docker question, but I'm wasting a lot of time and reading a lot of confusing stuff assuming that.

I notice after creating a container using the --hostname foo flag, phpinfo() outputs the name of the server as 'localhost':

$_SERVER['HTTP_HOST']: localhost:2550 $_SERVER['SERVER_NAME']: localhost

By adding 'foo' as an entry against 127.0.0.1 in /etc/hosts, I was able to change the latter value only, and of course I don't want to have to do that.

In container shell, output of hostname is (correctly) 'foo'.

There are a couple of specific reasons I need this in my Grav container:

I noticed #1 and that /etc/nginx/sites-enabled/default contains the line server_name $hostname;.

Seems I am either getting a docker create flag wrong or the image isn't configuring something it should. Are you able to point me in the right direction?

hughbris commented 4 years ago

Update: taking notes while I experiment a little more.

From a fresh container using:

$ docker create --name foo --restart unless-stopped -p 2560:80 -e DUID=1000 -e DGID=1000 --hostname foo --network bridge --dns-search local -v /data/containers/foo/backup:/var/www/grav/backup -v /data/containers/foo/logs:/var/www/grav/logs -v /data/containers/foo/user:/var/www/grav/user dsavell/grav

and then # echo '<?php phpinfo(); ?>' > _info.php into a shell at the web root path, I see:

$_SERVER['HTTP_HOST']: localhost:2560 $_SERVER['SERVER_NAME']: foo

Which contradicts what I saw last night when I wrote the issue out! (I'm going mad.) Also those two values don't agree. Nevermind that ..

So to test local environment config, I created /data/containers/foo/user/foo/config/system.yaml locally and put in simply:

debugger:
  enabled: true

Refresh .. no debug bar. Then I copied the file to a new local path at /data/containers/foo/user/localhost/config/system.yaml and voila we see the debug bar.

Ultimately, all I am concerned about is that Grav is not self-identifying its hostname correctly, which breaks a few things.

Hope that helps you reproduce the issue.

hughbris commented 4 years ago

I have a couple of workarounds now, which I'll put here on the off chance it's useful to someone else before you can look at this.

I trick Grav into loading the correct environment configuration directory at user/<env> by adding a symlink from user/localhost in each environment. That doesn't get committed to my repo and it needs to be set up in each environment while the problem persists.

I trick the login plugin (maybe other components) into providing correct absolute URLs by adding a custom_base_url property to each environment's user/<env>/config/system.yaml.

These hacks work around my issues :)

dsavell commented 4 years ago

Hey, I am not sure this is something I can fix, localhost is set as a generic config rather than "environment specific" config, any environment specific changes will need to be altered / configured by the end user i.e yourself. hence why you can mount in the config directories. Im going off the basis of this document: https://learn.getgrav.org/16/advanced/environment-config, as my image is just using "/var/www/grav/user".

This might be something to raise on the GRAV forums, as ultimately its still 1 web server running and only 1 php instance, so localhost here is the best option as these apps, will never know about the multi environment setup unless configured in that way.

I could be wrong, or im just getting confused on the requirement. correct me if I am wrong.

hughbris commented 4 years ago

FYI for some reason a localhost symlink isn't working on my latest containers, I using symlinking to 127.0.0.1 instead.

dsavell commented 1 year ago

Stale, please re-raise if still an issue