eko / docker-symfony

Run a Symfony application using Docker & docker-compose
BSD Zero Clause License
1.29k stars 474 forks source link

How to modify the internal URL? #135

Open automatix opened 3 years ago

automatix commented 3 years ago

Hi,

(Context: Windows 10.)

I was a bit unhappy with the naming and changed some names, e.g. the log files names or the database name. I'm going to create a PR later. Anyway, the last station on this road was the URL. So I changed the value of the server.server_name configuration in the symfony.conf from "symfony.localhost" to "app.loc". Then

$ docker-compose down && docker-compose build && docker-compose up -d

But no effect. The container can still be found under symfony.localhost. OK, then I removed all containers, images, volumes, and networks, cleared the build cache, executed docker system prune (which is actually not needed, when all the objects have already been removed by running specific commands -- but just in case).

$ docker container stop $(docker container ls -aq)
$ docker container rm $(docker container ls -aq)
$ docker image prune -a
$ docker volume prune
$ docker network prune
$ docker builder prune
$ docker system prune

Then I rebuilt and started the containers again.

$ docker-compose down && docker-compose build && docker-compose up -d

But I still cannot reach the application under the new address. And the old one is still working. How is it possible? How to get the change applied?

automatix commented 3 years ago

Resolved... ) I forgot to change the entry in the hosts of my host system:

127.0.0.1           app.loc

Now it works.

automatix commented 3 years ago

I'm reopening this issue, since there is still one thing, I cannot explain to myself:

The new address app.loc only wokrs, if it's registered in the hosts file. The old address works independently of the hosts. I can register it there, can remove, can set the address to -- the old one works in every case. Why? Is there a kind of cache? And why doesn't it work for the new address the same way?

eko commented 3 years ago

Hi @automatix,

I think this is because the symfony.localhost server name is hard coded into the nginx configuration here: https://github.com/eko/docker-symfony/blob/master/nginx/symfony.conf#L2

Maybe we could use server_name _; to have a catch-all domain names (see: http://nginx.org/en/docs/http/server_names.html).

ricfio commented 3 years ago

Hi @eko, is there any reason why nginx is not configured to serve the symfony application directly as the default server? If this were possible it would no longer be necessary to modify the hosts file !

PS Could be useful customizing the server_name (currently hard coded) on nginx configuration symfony.conf ?