访问Docker容器的端口

时间:2018-10-12 19:20:25

标签: docker nginx port

我的本​​地计算机上运行着两个网站:

App A:在docker中运行的wordpress应用,可通过以下方式访问: http://localhost:5000

应用B:本地Web服务器中正在运行的另一个应用 http://localhost:80

问题是,当我尝试访问wordpress控制面板(http://localhost:5000/wp-admin)时,浏览器显示“未找到”错误,浏览器地址栏上的URL显示“ http://localhost/wp-admin/”(端口5000自动消失)。

我的猜测是浏览器正在尝试从App B(端口80)而不是App A(端口5000)访问wp-admin。

这是为什么,以及如何强制浏览器使用我的特定端口?

我在Chrome和Firefox中都进行了测试,它们的行为相同。

这是我的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

我的nginx配置:

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;
    }    
}

0 个答案:

没有答案