Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy wont forward domain.com/<subdir> #87

Closed
fenpaws opened this issue Nov 14, 2018 · 10 comments
Closed

Proxy wont forward domain.com/<subdir> #87

fenpaws opened this issue Nov 14, 2018 · 10 comments

Comments

@fenpaws
Copy link

fenpaws commented Nov 14, 2018

Hello there, first of all, great proxy but I can't get it to work for me. I'm not the best in docker and I'm still learning so please forgive me when I ask stupid questions.

So this is my scenario, I want to proxy domain.com/wp1 to a WordPress container. The Wordpress container has two networks attached. one for the backend and one for the frontend. The backend one is used for communication between WordPress and mySQL Server. The frontend one is used to proxy the request domain.com/wp1 to the container.

I do this because I don't want that other containers can access my WordPress database.

And this approach worked somewhat. the proxy detects the container and generates a proxy directive

domain.com/wp1 {
  proxy / 172.19.0.3
}

But it, in the end, it won't work, I cannot access it.

The labels I uses are

labels:
  - caddy.address=domain.com/wp1
  - caddy.proxy.transparent

am i doing something wrong here?

@lucaslorentz
Copy link
Owner

What is 192.168.178.37?
Is it the IP of the docker host? Or is it the IP of your container? Or is it the IP of your caddy container?

@lucaslorentz
Copy link
Owner

Are you using docker swarm or docker compose to deploy a yaml file?

@fenpaws
Copy link
Author

fenpaws commented Nov 14, 2018

the IP 192.X.X.X is the docket host, I should have changed that in here.

I used a docker-conpose file to deploy the proxy and the WordPress containers

@fenpaws
Copy link
Author

fenpaws commented Nov 14, 2018

I edited my initial post to stop confusion about the IP, also I have forgotten to include the /wp1 after the domain.com part.

This is what it actually looks like, sorry my bad.

labels:
  - caddy.address=domain.com/wp1
  - caddy.proxy.transparent

@fenpaws
Copy link
Author

fenpaws commented Nov 18, 2018

Heya can you help me with it? I tried nearly anything and it won't work. Do you need more information about my problem?

@lucaslorentz
Copy link
Owner

lucaslorentz commented Nov 22, 2018

Well, I'm not sure if wordpress supports running entirely under a path (wp1).

I was able to get it partially working using settings WP_HOME and WP_SITEURL. But still wp-admin doesn't work very well, several times it redirects to a url without wp1.

See below a test I did for docker-compose, without swarm services:

version: '3.7'

services:
  caddy:
    image: lucaslorentz/caddy-docker-proxy:alpine
    ports:
      - 8080:80
    networks:
    - frontend
    command: -email email@example.com -agree=true -log stdout
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"

  wordpress:
    depends_on:
      - mysql
    image: wordpress:latest
    networks:
    - frontend
    - backend
    labels:
    - caddy.address=http://localhost/wp1
    - caddy.proxy.transparent
    environment:
      WORDPRESS_DB_HOST: mysql:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_CONFIG_EXTRA: |
        define( 'WP_HOME', 'http://localhost/wp1' );
        define( 'WP_SITEURL', 'http://localhost/wp1' );

  mysql:
    image: mysql:5.7
    networks:
    - backend
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

networks:
  frontend:
    driver: bridge
  backend:
    driver: bridge

Then hit http://localhost:8080/wp1

@lucaslorentz
Copy link
Owner

The issue is wp-canonical-admin url that is generated based on SERVER['REQUEST_URI'], which doesn't contain path wp1.
Didn't find any way to fix it by changing caddy proxy config.

@fenpaws
Copy link
Author

fenpaws commented Nov 26, 2018

Hmm okay, but I think that this issue only applies to WordPress right? What about my own sites that I write or different CMS, does this problem effect it too?

But thanks for your time to try to figure it out.
Really appreciated.

@lucaslorentz
Copy link
Owner

Well, it might affect several kind of applications/sites.
The main problem is proxying /folder to a site without /folder.
The site must generate all links and urls with /folder, even though all requests it receives doesn't have /folder.

If you proxy a subdomain instead of a folder, like: wp1.your-domain.com, you would face much less issues.

@fenpaws
Copy link
Author

fenpaws commented Dec 13, 2018

sorry for that really late answer, I know but for the intended purpose was this the only way. But my friend changed his mind and did the subdomain way. But thanks again for that help, I learned a bit from that :D

@fenpaws fenpaws closed this as completed Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants