How to access Docker Wordpress site without a hosts file entry?

Hi, I’ve searching for DAYS on how to do this but can’t find the answer. I am very new to Docker and server administration so please be patient.

I have set up a linux server running Ubuntu 16.04. This is what I’ve installed:

  1. NGINX container using the “nginx:latest” image.
  2. standard Wordpress in it’s own Container.
  3. standard MariaDB in it’s own conatiner
  4. created volumes to both wordpress and the DB and mounted them in the hosts file system so I can edit them.

I created the wordpress website as a virtual host. So after adding the public IP address and the virtual host name (for example, “mysite.com”) to my local computers hosts file, I can see the wordpress site in my browser. No problem.

The issue I have is that I need other people to be able to view the site in their browser, but they can’t make changes to their hosts file and they can’t use CharlesProxy to do DNS Spoofing.

I have been searching for days trying to find a way to access the site without adding the hosts entry. It can’t be that difficult? Please help!

Here is an excerpt from my conf.d/default.conf file:
upstream mysite.com {
## Can be connect with “bridge” network
# mysite_wordpress_1
server xxx.xx.x.x:80;
}
server {
server_name mysite.com;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
include /etc/nginx/vhost.d/mysite.com;
location / {
proxy_pass http://mysite.com;
}
}

It sounds like you need an ordinary DNS hosting service. If you were already on Amazon, their Route 53 service is straightforward, but I know there are hundreds of readily available alternatives.

You need to make sure there exists a DNS A record that points at your public IP address, and make sure your container is publishing on the host’s port 80 (or 443) and it’s not firewalled off. But it sounds like your core question isn’t especially Docker-specific; you’d have the same issue if you were running Wordpress/nginx without Docker.

Hi dmaze, thank you for responding and I apologize if I’m asking really naive questions. My server is on an Azure VM. So I believe I have the public IP you mentioned. It’s like mydomain.westus.cloudapp.azure.com

I want to be able to set up two wordpress sites, mydomain.westus.cloudapp.azure.com/mysite1 and mydomain.westus.cloudapp.azure.com/mysite2, with mysite1 and mysite2 each in their own Docker container.

When I don’t use docker, I have my /var/www/html directory and I can reach my default index.html file by going to mydomain.westus.cloudapp.azure.com
When I put a test.php file at /var/www/html/test.php and go to mydomain.westus.cloudapp.azure.com/test.php I get a 502 Bad Gateway error. This is without being in a Docker container.

This is my default.conf file:

server {
listen 80 default_server;
listen [::]:80 default_server;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html index.php;

    location ~ [^/]\.php(/|$) {
            fastcgi_split_path_info ^(.+?\.php)(/.*)$;
            if (!-f $document_root$fastcgi_script_name) {
                    return 404;
            }

            # Mitigate https://httpoxy.org/ vulnerabilities
            fastcgi_param HTTP_PROXY "";
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
    }

}

Again, sorry for all the questions but I’m totally confused :frowning: