3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

macOSのhostsファイルではポート番号は指定できない

Posted at

自分の中で曖昧で忘れそうなのでメモします。

状況|前提

docker-machine上にdocker-compose+Dockerfileでnginxコンテナを立てて
開発環境を作成しているところでポート、IPの設定が曖昧で少しはまった状態。
192.168~:8080でwelcome to nginxは出るものの
テスト環境用のドメイン、example.comではアクセスできなかった。

error.hosts

192.168~ example.com:8080

docker-machine ls時のURLが
tcp://192.168~:2376

docker container ls した時のportsの部分が
8080/tcp, 0.0.0.0:8080->80/tcp

という状況でした。

machineにIP192.168が割り当てられ
0.0.0.0はhostOS(macOS)自身を指している?
docker-machineの8080で受けたものをnginxの80に渡している?
この辺り解釈が曖昧で恐縮です。間違っていたら突っ込みいただけたら嬉しいです。

hostsファイルで指定できるのはIPとホスト名(ドメイン)だけ

参考サイト1
これがはっきりして助かりました。

アクセスできるようになった設定

以下の設定でアクセスしたところOKでした。

ok.hosts

192.168~ example.com

/etc/nginx/conf.d/example.conf

server {
    listen       80;
    server_name  example.com;

    location / {
        root   /app/example;
        index  index.html index.htm;
    }
}

↑の設定にして
example.com:8080
でアクセスすると見れました。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?