LoginSignup
0
0

More than 1 year has passed since last update.

【nginx】ローカルDockerでリバースプロキシを設定する

Last updated at Posted at 2021-07-01

「nginxでリバースプロキシの設定が動かない!助けて!」という依頼を受けた際に、ローカルDockerで環境を作って動作確認した際のメモ

環境

  • macOS BigSur(11.2.3) ※ Intelチップ
  • docker desktop(3.2.2)

手順

1. リバースプロキシ用の設定ファイルを用意

default.conf
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    location ^~ /sub_directory/ {
      proxy_set_header X-Real-IP  $remote_addr;
      proxy_set_header X-Forwarded-Proto https;
      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Server $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_pass {{ 接続先URL or IP }};
    }
}

2. nginxコンテナ立ち上げ

docker run --name hogehoge -v /Users/user_name/default.conf:/etc/nginx/conf.d/default.conf:ro -p 8080:80 nginx

3. 動作確認

confファイルのproxy_pass

proxy_pass http://hogehoge.com/test

上記のような設定をしている場合は、
http://localhost:8080/sub_directory のアクセスが
http://hogehoge.com/test にリバースプロキシされる

参考

0
0
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
0
0