9
7

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.

github-pagesへnginxからredirect

Posted at

nginx redirect to Github Pages

つまり

とあって、リバースプロキシ nginx を使って、github-pagesのインフラを使わせてもらおうという話。

まずgithub-pages

  1. Githubでプロジェクトを作る。今回は takagi.makei.nu
  2. gh-pages というブランチを作る
  3. コンテンツを書く
  4. http://pharaohkj.github.io/takagi.makei.nu/ でページが見られるのを確認する。

nginxのconfを書く

  1. CentOSのパッケージでは /etc/nginx/conf.d/xxx.confに書く流儀らしいので、/etc/nginx/conf.d/takagimakei.nu.confを作成
  2. 中身はこんな感じ
  • server_name は cname/a レコードで設定したもの
  • redirectのログは出しておく(noticeじゃないと出ないらしい)
  • 書いたら /etc/init.d/nginx configtest からの service nginx reload
server {
        access_log /var/log/nginx/takagi.makei.nu.access.log main;
        error_log /var/log/nginx/takagi.makei.nu.error.log notice;
        server_name takagi.makei.nu;
        rewrite_log on;
        # rewrite ^(.*) http://pharaohkj.github.io/takagi.makei.nu$1 ;
        location / {
                rewrite ^/(.+) $1 break;
                proxy_pass http://pharaohkj.github.io/takagi.makei.nu/$1;
        }
}

テスト

curlを詳細出力実行でヘッダやレスポンスがみられてわかりやすい。あと、nginxのログも見ること。rewriteはハマりやすい。

$ curl http://takagi.makei.nu -v
* STATE: INIT => CONNECT handle 0x60002d7e0; line 1011 (connection #-5000)
* Rebuilt URL to: http://takagi.makei.nu/
* Hostname was NOT found in DNS cache
*   Trying 49.212.145.99...
* Adding handle: conn: 0x60006a4d0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* 0x60002d7e0 is at send pipe head!
* - Conn 0 (0x60006a4d0) send_pipe: 1, recv_pipe: 0
* STATE: CONNECT => WAITCONNECT handle 0x60002d7e0; line 1058 (connection #0)
* Connected to takagi.makei.nu (49.212.145.99) port 80 (#0)
* STATE: WAITCONNECT => DO handle 0x60002d7e0; line 1177 (connection #0)
> GET / HTTP/1.1
> User-Agent: curl/7.37.0
> Host: takagi.makei.nu
> Accept: */*
>
* STATE: DO => DO_DONE handle 0x60002d7e0; line 1263 (connection #0)
* STATE: DO_DONE => WAITPERFORM handle 0x60002d7e0; line 1384 (connection #0)
* STATE: WAITPERFORM => PERFORM handle 0x60002d7e0; line 1395 (connection #0)
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 200 OK
* Server nginx/1.6.0 is not blacklisted
< Server: nginx/1.6.0
< Date: Tue, 16 Sep 2014 10:13:24 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 1041
< Connection: keep-alive
< Last-Modified: Tue, 16 Sep 2014 04:04:34 GMT
< Expires: Tue, 16 Sep 2014 10:23:24 GMT
< Cache-Control: max-age=600
< Accept-Ranges: bytes
< Via: 1.1 varnish
< Age: 0
< X-Served-By: cache-ty68-TYO
< X-Cache: MISS
< X-Cache-Hits: 0
< X-Timer: S1410862404.676017,VS0,VE170
< Vary: Accept-Encoding
<

(コンテンツの中身)

9
7
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?