Solution for Configure Apache server dns with nginx container
is Given Below:
I created a webapp with 3 containers. Nginx, postgresql and php.
In every computer I tested it, it worked without problems.
In docker-compose I mapped the port 8082 to 80.
I had to put it in the “real” server and they needed to map the localhost:8082 of the server, where the webapp is running to a real address.
The problem is that the page seems to load the views but it doesn’t load the js and css
On the console, if i go to xxx.yyy.it, I can see that it cannot load “http: // localhost:8082/output/final.js”.
But if, in the browser, I write “http: // xxx.yyy.it/output/final.js”, I can see the js file
I really don’t know how Apache or Nginx server work. It seems it is not transforming the localhost:8082 to the xxx.yyy.it
They prepared, inside the sites-available of /etc/apache2 of the server:
<VirtualHost *:80>
ServerName xxx.yyy.it
ProxyPass / http://localhost:8082/
#ProxyPassReverse / http://localhost:8082/
</VirtualHost>
The docker-compose is configured as:
nginx:
image: nginx:stable-alpine
container_name: nginx
ports:
- "8082:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
- database
and the default.conf of the nginx container is this:
server {
listen 80;
index index.php index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ .php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Is there a way i can tell the Apache server to always transform localhost:8082 to xxx.yyy.it?