Question

Redirect to different port when url start with a specific path/string

Posted February 20, 2020 122 views
Docker

Hi all!
I created a website using WordPress and next.js, all using Docker. My frontend part (next.js) is exposed on port 80 so I can see my site when I write the correct URL. Wordpress is exposed to port 8080 and to access my admin part I need to write MY_IP:8080/wp-admin/.

I would like to find a way to see the content of MY_IP:8080/wp-admin/ every time I write the URL of my website like this MY_URL/wp-admin/ but of course, continuing to see the URL with the right name of my site (MY_URL/wp-admin/) and not with MY_IP:8080/wp-admin/.

Of course, I need this logic also for any subfolder/file when the path starts with wp-admin (i.e. MY_URL/wp-admin/post.php?post=320&action=edit).

Does somebody know what I need to check for making this possible?

edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hello,

What you could do is install Nginx and use it as a reverse proxy for your Wordpress website which is running inside your Docker container on port 8080.

The Nginx reverse proxy that you could use, should look something like this:

server {
  listen 80;
  server_name www.yourdomain.com; # change this

  # global gzip on
  gzip on;
  gzip_min_length 10240;
  gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
  gzip_disable "MSIE [1-6]\.";

  add_header Cache-Control public;

  location / {
    proxy_pass http://127.0.0.1:8080; # change this
    proxy_buffering on;
    proxy_buffers 12 12k;
    proxy_redirect off;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
  }


}

Also, you could take a look at this answer here on how to host multiple Docker containers one server with Nginx:

https://www.digitalocean.com/community/questions/how-to-host-multiple-docker-containers-on-a-single-droplet-with-nginx-reverse-proxy

Hope that this helps!
Regards,
Bobby

Submit an Answer