在不同的端口上运行不同的docker nginx容器

好吧,我有简单的docker集,这是默认configuration做得很好。 这是我docker-compose.yml

 version: '3.1' services: mysql: image: mysql ports: - ${MYSQL_PORT}:3306 environment: MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASS} MYSQL_DATABASE: ${MYSQL_DB} MYSQL_USER: ${MYSQL_USER} MYSQL_PASSWORD: ${MYSQL_PASS} volumes: - mysql_data:/var/lib/mysql php: image: some_repo/php:latest volumes: - .:/var/www/html nginx: image: some_repo/nginx:latest ports: - ${NGINX_PORT}:80 links: - php volumes: - ./docker/vhost/:/etc/nginx/sites-available - .:/var/www/html volumes: mysql_data: 

在其他文件中,我有所有variables的值 – 例如更改mysql的端口效果很好。

这是我的vhost

 server { server_name test.dev; root /var/www/html; location / { try_files $uri @rewriteapp; } location @rewriteapp { rewrite ^(.*)$ /index.php/$1 last; } location ~ ^/(index)\.php(/|$) { fastcgi_pass php-upstream; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; } error_log /var/log/nginx/docker_error.log; } 

我在nginx上有几个项目,有时我需要同时运行它们,这里是问题所在。 我试图configuration每一个nginx容器运行在不同的端口,但没有运气。 在etc/hosts我只有127.0.0.1 test.dev ,据我所知,端口对该文件无关紧要。

我试图添加到vhost文件一些listen 98; 或者一些东西,但是在不同的端口上运行nginx是不够的 – 当我点击test.dev ,浏览器中的test.devConnection resetConnection reset Connection refused