Skip to content

Instantly share code, notes, and snippets.

@AKB428
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AKB428/74bed7d838cf0ca913f1 to your computer and use it in GitHub Desktop.
Save AKB428/74bed7d838cf0ca913f1 to your computer and use it in GitHub Desktop.
[Mastering DMP] Chapter 02

#第2章 Play FrameworkとNginxを連携する

NginxへのリクエストをPlay Frameworkへ渡す

Imgur

このシステム概要図の

mdpp:8080 -> localhost:9090 の設定を行う

DMPサーバー用のnginx.conf設定

vi /usr/local/etc/nginx/nginx.dev_mdmp.conf

worker_processes auto;
pid  /var/run/nginx.mdmp.pid;

events {
    worker_connections  1024;
}

http {
    upstream play-mdmp {
        server localhost:9000;
    }

    server {
        listen       8080;
        server_name  _;

        location /1.gif {
            proxy_pass http://play-mdmp;
        }
    }
}

Nginx再起動

sudo nginx -c /usr/local/etc/nginx/nginx.dev_mdmp.conf -s reload

mdmp.com:8080にアクセス

http://mdmp.com:8080/1.gif

ブラウザでアクセスしHTTP通信が成功すれば成功。

ChromeのEditCookieは以下のようになる。

EditCokkie

ダミーサービスのNginx設定

hotel.com,travel.com,nodazon.comのNginx設定

vi /usr/local/etc/nginx/nginx.dummy_service.conf

worker_processes auto;

pid  /var/run/nginx.dummy_serv.pid;

events {
    worker_connections  1024;
}

http {
    server {
        listen       80;
        server_name  _;
        location / {
          root /usr/local/var/www;
          index index.html;
        }
    }
    #hotel.com
    server {
       listen       80;
       server_name hotel.com;
       access_log  /usr/local/var/log/nginx/access.hotel.com.log;
       location / {
        root   /usr/local/var/www/hotel;
        index  index.html;
       }
    }
   #travel.com
    server {
       listen       80;
       server_name travel.com;
       access_log  /usr/local/var/log/nginx/access.travel.com.log;
       location / {
        root   /usr/local/var/www/travel;
        index  index.html;
       }
    }
   #nodazon.com
    server {
       listen       80;
       server_name nodazon.com;
       access_log  /usr/local/var/log/nginx/access.nodazon.com.log;
       location / {
        root   /usr/local/var/www/nodazon;
        index  index.html;
       }
   }
}

Nginx起動

sudo nginx -c /usr/local/etc/nginx/nginx.dummy_service.conf

サービスサイトにトラッキングタグの埋め込みを行う

cd /usr/local/var/www
mkdir hotel
mkdir travel
mkdir nodazon


vi hotel/index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to Hotel.com</title>
</head>
<body>
<h1>Welcome to Hotel.com</h1>
<img src="//mdmp.com:8080/1.gif" style="display:none">
</body>
</html>

vi travel/index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to travel.com</title>
</head>
<body>
<h1>Welcome to travel.com</h1>
<img src="//mdmp.com:8080/1.gif" style="display:none">
</body>
</html>

vi nodazon/index.html
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nodazon.com</title>
</head>
<body>
<h1>Welcome to nodazon.com</h1>
<img src="//mdmp.com:8080/1.gif" style="display:none">
</body>
</html>

動作確認

Chromeのディベロッパーツールを使いmdmp.com:8080/1.gif が正しく取得されているか、Cookieが発行されているか、Cokkieがある場合は再発行されていないか、Cokkieの有効期限が更新されているかを確認する。

devtool

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment