1

I have two websites running in my local computer:

App A: a wordpress app running in docker and is accessible from this: http://localhost:5000

App B: another app running in the local web server http://localhost:80

The problem is, when I try to access the wordpress control panel (http://localhost:5000/wp-admin), the browser shows NOT Found error, and the URL on the browser address bar shows "http://localhost/wp-admin/" (port 5000 automatically disappeared).

My guess is that the browser is trying to access wp-admin from App B (port 80) instead of App A (port 5000).

Why is that and how to force browser to use my specificed port?

I tested in both Chrome and Firefox, they behave the same.

This is my docker-compose.yml:

version: '3'

services:
  service_website:
    build: ./services/website
    volumes:
      - ./services/website/source:/var/www/app
      - ./services/website/config/nginx.site.conf:/etc/nginx/conf.d/default.conf
    ports:
      - 5000:80

  php:
    build: ./services/php-fpm
    volumes:
      - ./services/website/source:/var/www/app
      - ./services/php-fpm/config/php.ini:/usr/local/etc/php/php.ini

my nginx config:

server {
    index index.html index.php;
    listen 80 default_server;
    server_name localhost php-docker.local;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;    
    root /var/www/app/public;

    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;
    }    
}
LazNiko
  • 2,083
  • 3
  • 25
  • 39
  • How do you run your docker container? – Amr Aly Oct 12 '18 at 19:25
  • 1
    added the docker-compose.yml, and i run it with "docker-compose up" – LazNiko Oct 12 '18 at 19:32
  • Your port is setup correctly. what about your nginx configurations. – Amr Aly Oct 12 '18 at 20:29
  • have you connected your `php` service with required ports? I don't see a port thing in the `.yml` file – scipsycho Oct 13 '18 at 13:14
  • @AmrAly I have uploaded the nginx conf - – LazNiko Oct 14 '18 at 07:29
  • @scipsycho what would you suggest to add the ports? – LazNiko Oct 14 '18 at 07:29
  • @LazNiko what I am suggesting is try connecting the `php` service to port 80 of the host and if your browser is trying to access http://localhost:80 instead of http://localhost:5000 then you will know for sure otherwise the problem has nothing to do with the app B. – scipsycho Oct 14 '18 at 09:02
  • Please check this [answer](https://serverfault.com/questions/227742/prevent-port-change-on-redirect-in-nginx) – Amr Aly Oct 14 '18 at 12:47
  • @AmrAly Have added "port_in_redirect off;" as mentioned in that post, still not working. However, if I add a slash at the end (i.e. "http :// localhost:5000 / wp-admin /" [ending with a slash] instead of "http://localhost:5000/wp-admin" [without the ending slash]), then it works. Can't understand why the slash affects the port..... – LazNiko Oct 17 '18 at 16:47
  • also added "absolute_redirect off;" in nginx config file, still no luck. – LazNiko Oct 17 '18 at 17:20
  • could it be the settings in your dashboard? check [this](https://wordpress.stackexchange.com/questions/89544/wordpress-local-host-web-login-not-working-after-port-configuration) – Amr Aly Oct 18 '18 at 15:40
  • @AmrAly my site url and home is already set to http://localhost:5000/ - still the same. – LazNiko Oct 19 '18 at 16:47

0 Answers0