投稿者: chombo

  • 一つのApache設定ファイルを複数のPCで使う

     自宅とAWS上でほぼ同じ内容のWebサーバーを稼働させている。

    • OS: Windows Server 2016
    • Server version: Apache/2.4.43 (Win64)

     コンテンツはほぼ同じなのだが、ドメイン名とか違っているのでhttpd.confなどがそれぞれ別の内容になっている。

     似たような内容が2か所にコピーされているのは間違いの元なので、一つのconfファイルが使えないかといろいろ試していてやっと実現できた。

     confファイルの中で分岐させるのは<If>とか<SetEnvIf>とか<IfDefine>とかあるけど、<If>とかは実行時にページを要求されるごとに評価されるためか、うまく動かなかった。

     <IfDefine>は起動時に評価されるため、なんとか実現できた模様。

     以下はPC1という名前とPC2という名前の二つのPCが、それぞれdomain1.com,domaein2.comとうドメインを運用している前提で説明する。

    httpd.confでApacheの環境変数を定義する。

    Define COMPUTER_${COMPUTERNAME}
    <IfDefine COMPUTER_PC1>
        Define DOMAIN "domain1.com"
    </ifDefine>
    <IfDefine COMPUTER_PC2>
        Define DOMAIN "domain2.com"
    </ifDefine>

     PCのシステム環境変数COMPUTERNAMEを使ってそれぞれ別のApache環境変数を定義している。

     httpd-vhosts.confなどでは<IfDefine>を使ってそれぞれ固有の設定を記述する。

    <IfDefine COMPUTER_PC1>
    <Directory "C:/xampp/htdocs">
        Options FollowSymLinks
        AllowOverride All
        Require all denied
        Require ip ${IPADDR_LOCAL}
    </Directory>
    </IfDefine>
    
    <IfDefine COMPUTER_PC2>
    <Directory "C:/xampp/htdocs">
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    </IfDefine>
    
    <VirtualHost *:80>
        ServerAdmin postmaster@${DOMAIN}
        DocumentRoot "C:/xampp/htdocs"
        ServerName www.${DOMAIN}
        ServerAlias ${DOMAIN}
        ErrorLog  "| bin/rotatelogs.exe logs/${DOMAIN}-error_%Y-%m.log  86400"
        CustomLog "| bin/rotatelogs.exe logs/${DOMAIN}-access_%Y-%m.log 86400"
    </VirtualHost>

     上記はPC1だけIPアドレスによるアクセス制限をかけている。

     VirtualHostは、それぞれのドメインを同じ記述で別の定義を行っている。

     それぞれのPC上で、以下のコマンドを使って実行時に設定されている内容を確認する。

    httpd.exe -S                  VirtualHostの確認
    httpd.exe -t -DDUMP_CONFIG    設定の確認
  • WordPress 参加申込フォーム作成

     参加している趣味の団体で、年一回開催しているイベントの参加申込をWordPressでできるようにしたい。

     フォームのプラグインは有名どころだとContact Form 7とWM WP Formがあるみたいなので、とりあえず両方作ってみた。

     プラグインはContact Form 7とその履歴を保存できるFlamingo、WM WP Formを追加する。

     ついでに、郵便番号から住所を自動入力できるyubinbangoも入れておく。

     フォームには定番の氏名、生年月日、住所、メールアドレスなどを入力できるようにしておいた。

    MW WP Form版

    <script src="https://yubinbango.github.io/yubinbango/yubinbango.js" charset="UTF-8"></script>
    <script> document.querySelector('.mw_wp_form_input form').classList.add('h-adr'); </script>
    <span class="p-country-name" style="display:none;">Japan</span>
    
    xxxに参加申し込みします
    <table class="table-res-form">
    <tbody>
    <tr>
    <th>氏名<span class="requied">必須</span></th>
    <td>[mwform_text name="lastname" size="12" placeholder="姓"]</td>
    <td>[mwform_text name="firstname" size="12" placeholder="名"]</td>
    </tr>
    <tr>
    <th>ふりがな<span class="requied">必須</span></th>
    <td>[mwform_text name="lastkana" size="12" placeholder="せい"]</td>
    <td>[mwform_text name="firstkana" size="12" placeholder="めい"]</td>
    </tr>
    <tr>
    <th>生年月日<span class="requied">必須</span></th>
    <td colspan="2">[mwform_select name="birth-year" children="1920,1921,1922,1923,1924,1925,1926,1927,1928,1929,1930,1931,1932,1933,1934,1935,1936,1937,1938,1939,1940,1941,1942,1943,1944,1945,1946,1947,1948,1949,1950,1951,1952,1953,1954,1955,1956,1957,1958,1959,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036,2037,2038" value="1980"]年 [mwform_select name="birth-month" children="-,1,2,3,4,5,6,7,8,9,10,11,12"]月 [mwform_select name="birth-day" children="-,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31"]日</td>
    </tr>
    <tr>
    <th>性別<span class="requied">必須</span></th>
    <td colspan="2">[mwform_radio name="gender" children="男,女"]</td>
    </tr>
    <tr>
    <th>郵便番号<span class="requied">必須</span></th>
    <td colspan="2">[mwform_text name="zipcode" class="p-postal-code" conv_half_alphanumeric="true" size="10" maxlength="7" placeholder="0000000"]</td>
    </tr>
    <tr>
    <th>都道府県<span class="requied">必須</span></th>
    <td colspan="2">[mwform_select name="pref" class="p-region" children="-,北海道,青森県,岩手県,宮城県,秋田県,山形県,福島県,茨城県,栃木県,群馬県,埼玉県,千葉県,東京都,神奈川県,新潟県,富山県,石川県,福井県,山梨県,長野県,岐阜県,静岡県,愛知県,三重県,滋賀県,京都府,大阪府,兵庫県,奈良県,和歌山県,鳥取県,島根県,岡山県,広島県,山口県,徳島県,香川県,愛媛県,高知県,福岡県,佐賀県,長崎県,熊本県,大分県,宮崎県,鹿児島県,沖縄県" value"長野県"]</td>
    </tr>
    <tr>
    <th>市町村区<span class="requied">必須</span></th>
    <td colspan="2">[mwform_text name="city" class="p-locality" size="20" placeholder="市町村"]</td>
    </tr>
    <tr>
    <th>番地等<span class="requied">必須</span></th>
    <td colspan="2">[mwform_text name="addr1" class="p-street-address p-extended-address" size="40" placeholder="番地等"]</td>
    </tr>
    <tr>
    <th>建物名等</th>
    <td colspan="2">[mwform_text name="addr2" size="40" placeholder="建物名等"]</td>
    </tr>
    <tr>
    <th>電話番号<span class="requied">必須</span></th>
    <td colspan="2">[mwform_text name="phone" size="20" maxlength="15"]</td>
    </tr>
    <tr>
    <th>メールアドレス<span class="requied">必須</span></th>
    <td colspan="2">[mwform_email name="email" size="40"]</td>
    </tr>
    <tr>
    <th>その他</th>
    <td colspan="2">[mwform_textarea name="etc" cols="40" rows="5" ]</td>
    </tr>
    </tbody>
    </table>
    <p style="text-align: center;">[mwform_bconfirm class="確認" value="confirm"]確認画面へ[/mwform_bconfirm]
    [mwform_bback value="back"]戻る[/mwform_bback][mwform_bsubmit name="送信" value="send"]送信する[/mwform_bsubmit]</p>

    Contact Form 7版

    固定ページなどに張り込むショートコードにhtml_classを追加する。

    [contact-form-7 id="nnn" title="xxx" html_class="h-adr"]
    <script src="https://yubinbango.github.io/yubinbango/yubinbango.js" charset="UTF-8"></script>
    <span class="p-country-name" style="display:none;">Japan</span>
    
    xxxに参加申し込みします
    <table class="table-res-form">
    <tbody>
    <tr>
    <th>氏名<span class="requied">必須</span></th>
    <td>[text* lastname size:12 placeholder"姓"]</td>
    <td>[text* firstname size:12 placeholder"名"]</td>
    </tr>
    <tr>
    <th>ふりがな<span class="requied">必須</span></th>
    <td>[text* lastkana size:12 placeholder"せい"]</td>
    <td>[text* firstkana size:12 placeholder"めい"]</td>
    </tr>
    <tr>
    <th>生年月日<span class="requied">必須</span></th>
    <td colspan=2>[select* birth-year default:61 "1920" "1921" "1922" "1923" "1924" "1925" "1926" "1927" "1928" "1929" "1930" "1931" "1932" "1933" "1934" "1935" "1936" "1937" "1938" "1939" "1940" "1941" "1942" "1943" "1944" "1945" "1946" "1947" "1948" "1949" "1950" "1951" "1952" "1953" "1954" "1955" "1956" "1957" "1958" "1959" "1960" "1961" "1962" "1963" "1964" "1965" "1966" "1967" "1968" "1969" "1970" "1971" "1972" "1973" "1974" "1975" "1976" "1977" "1978" "1979" "1980" "1981" "1982" "1983" "1984" "1985" "1986" "1987" "1988" "1989" "1990" "1991" "1992" "1993" "1994" "1995" "1996" "1997" "1998" "1999" "2000" "2001" "2002" "2003" "2004" "2005" "2006" "2007" "2008" "2009" "2010" "2011" "2012" "2013" "2014" "2015" "2016" "2017" "2018" "2019" "2020" "2021" "2022" "2023" "2024" "2025" "2026" "2027" "2028" "2029" "2030" "2031" "2032" "2033" "2034" "2035" "2036" "2037" "2038"] [select* birth-month include_blank "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12"]月 [select* birth-day include_blank "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30" "31"]日</td>
    </tr>
    <tr>
    <th>性別<span class="requied">必須</span></th>
    <td colspan=2>[radio gender default:0 "男" "女"]</td>
    </tr>
    <tr>
    <th>郵便番号<span class="requied">必須</span></th>
    <td colspan=2>[text* zipcode class:p-postal-code size:10 minlength:7 maxlength:7 placeholder"0000000"]</td>
    </tr>
    <tr>
    <th>都道府県<span class="requied">必須</span></th>
    <td colspan=2>[select* pref class:p-region default:20 "北海道" "青森県" "岩手県" "宮城県" "秋田県" "山形県" "福島県" "茨城県" "栃木県" "群馬県" "埼玉県" "千葉県" "東京都" "神奈川県" "新潟県" "富山県" "石川県" "福井県" "山梨県" "長野県" "岐阜県" "静岡県" "愛知県" "三重県" "滋賀県" "京都府" "大阪府" "兵庫県" "奈良県" "和歌山県" "鳥取県" "島根県" "岡山県" "広島県" "山口県" "徳島県" "香川県" "愛媛県" "高知県" "福岡県" "佐賀県" "長崎県" "熊本県" "大分県" "宮崎県" "鹿児島県" "沖縄県"]</td>
    </tr>
    <tr>
    <th>市町村区<span class="requied">必須</span></th>
    <td colspan=2>[text* city class:p-locality size:10 placeholder"市町村"]</td>
    </tr>
    <tr>
    <th>番地等<span class="requied">必須</span></th>
    <td colspan=2>[text* addr1 class:p-street-address class:p-extended-address placeholder"番地等"]</td>
    </tr>
    <tr>
    <th>建物名等</th>
    <td colspan=2>[text addr2 placeholder"建物名等"]</td>
    </tr>
    <tr>
    <th>電話番号<span class="requied">必須</span></th>
    <td colspan=2>[tel* phone]</td>
    </tr>
    <tr>
    <th>メールアドレス<span class="requied">必須</span></th>
    <td colspan=2>[email* email ]</td>
    </tr>
    <tr>
    <th>その他</th>
    <td colspan=2>[textarea etc ]</td>
    </tr>
    <tr>
    <td colspan=3><div align="center">[submit "送信"]</div></td>
    </tr>
    </tbody>
    </table>

    外観-カスタマイズで追加CSSに追加して、表示を整形する。

    以下の頁を一部参考にさせてもらっています。

    https://tonari-it.com/contactform7-form-design/

    /* ContactForm7のテーブル化レスポンシブ調整 */
    .entry-content > *:not(.alignwide):not(.alignfull):not(.alignleft):not(.alignright):not(.is-style-wide) {
    	max-width: 70rem;
    	width: calc(100% - 4rem);
    }
    /*テーブルを親要素の幅いっぱいに伸ばす*/
    .table-res-form {
        width: 100%;
    }
    /*一行ごとに上ボーダー*/
    .table-res-form tr {
        border-top: 1px #DDD solid;
    }
    /*一番上の行だけボーダーなし*/
    .table-res-form tr:first-child {
        border-top: none;
    }
    /*奇数行だけ背景色つける*/
    .table-res-form tr:nth-child(2n+1) {
        background: #eee;
    }
    /*thとtd内の余白指定*/
    .table-res-form th, .table-res-form td {
        padding: 1.0em;
    }
    /*th(項目欄)は30%幅、テキストを右寄せ*/
    .table-res-form th {
        width: 30%;
        text-align: right;
    }
    /*「必須」「任意」部分のスタイリング*/
    .table-res-form .requied, .optional{
        font-size: 50%;
        color: #FFF;
        height: 0;
        line-height: 1;
        vertical-align: baseline;
         position: relative;
        bottom: 1ex;
    }
    .table-res-form .requied {
        background: red;
    }
    .table-res-form .optional {
        background: blue;
    }
    
    /*ここから768px以下の指定*/
    
    @media only screen and (max-width: 768px) {
    /*thとtdをブロック化して幅100%にして、縦積み*/
        .table-res-form th, .table-res-form td {
            width: 100%;
            display: block;
        }
    /*th(項目名)欄の不要な余白削除・テキスト左寄せ*/
        .table-res-form th {
            padding-bottom: 0;
            text-align: left;
        }
    /*不要な最終行の左のthを非表示にする*/
        .table-res-form .empty {
            display: none;
        }
    }
    
    /*ここまで768px以下の指定---終わり*/
    
    /*ここから入力欄のスタイル指定*/
    
    /*各入力フォームスタイリング*/
    .table-res-form input[type="text"], input[type="email"], input[type="tel"], textarea {
        border: 1px #89BDDE solid;
        padding: 0.5em;
        border-radius: 5px;
        margin-bottom: 0.5em;
        width: auto;
    }
    /*入力欄にフォーカスしたら変化*/
    .table-res-form input[type="text"]:focus, textarea:focus {
        background: #EEFFFF;
        box-shadow: 0 0 1px 0 rgba(0, 0, 0, 0.5);
    }
    /*送信ボタンスタイリング*/
    .table-res-form input[type="submit"] {
        border: 1px #89BDDE solid;
        padding: 0.5em 4em;
        border-radius: 5px;
        background: #4C9ED9;
        color: #fff;
        box-shadow: 0 0 1px 0 rgba(0, 0, 0, 0.5);
        font-weight: bold;
    }
    /*送信ボタン・マウスオーバー時スタイリング*/
    .table-res-form input[type="submit"]:hover {
        background: #006599;
        box-shadow: none;
    }
    
    /* MW WP Formのラジオボタンを横並びにする */
    .mwform-radio-field {
    	display: inline-flex;
    }
    
  • AWS メール制限の解除

    EC2ではポート25利用制限、メール送信数制限が行われているため、制限の解除と逆引きDNS設定をおこなった。

    これは一回の申請ですべて可能。

    以下のアドレスを開き、入力する。

    https://console.aws.amazon.com/support/contacts?#/rdns-limits

    Email address: xxx@domain.com
    Use case description: メールサーバー構築のため。(rDNS registration.)
    Elastic IP address - optional: xxx.xxx.xxx.xxx
    Reverse DNS record - optional: mail.domain.com

    ほどなく、以下の受け付けメールが届いた。

    題名: Your AWS Inquiry [99999]
    差出人: Amazon Web Services
    
    Hello,
    
    Thank you for contacting Amazon Web Services. We have received your request and will begin reviewing soon.
    
    Your request tracking ID is: 99999
    
    Requests are evaluated in the order in which they are received. AWS is committed to being responsive and keeping you informed of our progress. You should expect to receive a non-automated response to your initial contact within 48 business hours, however please be aware that evaluation may take longer depending on the complexity of the request.
    省略…

    一時間ほどして追加情報の問い合わせメールが届いた。

    題名 : Your AWS Inquiry [99999]
    差出人 :Amazon Web Services
    
    Hello,
    
    Thank you for submitting your request to have the email sending limit removed from your account and/or for an rDNS update.
    
    In order for us to process this request as quickly as possible, please provide the following information:
    
    -A clear/detailed use-case for sending mail from EC2.
    
    -What type of configuration or setup have you implemented to prevent spam from originating from your EC2 resource?
    
    Please reply directly to this message with the above information. Once this has been received we can process your original request. As a reference, please make sure to review the AWS Acceptable Use Policy (https://aws.amazon.com/aup/)
    for more information regarding prohibited uses of AWS services.
    
    We appreciate your cooperation, if you have any questions, please reach out to us.
    
    Regards,
    Amazon Web Services
    このリクエストをできる限り迅速に処理するために、次の情報を提供してください。
    
    -EC2からメールを送信するための明確で詳細なユースケース。
    
    -EC2リソースからスパムが送信されるのを防ぐために、どのような構成または設定を実装しましたか?
    
    上記の情報を添えて、このメッセージに直接返信してください。これを受け取ったら、元のリクエストを処理できます。参照として、AWSの利用規定(https://aws.amazon.com/aup/)を必ず確認してください

    これに関して以下のようにメールを返した。

    Hello, 
    
    Thank you for your inquiry
    
    Run WordPress on Windows Serer 2016 on Lightsail and open a blog. Hobby club (about 30 people) shares information among members and manages mailing list.
    Announce an event (about 50 people) that is held once a year and accept participation.
    
    Emails will only be sent to the email address requested in advance or on the web, 
    
    Regards, please
    nnnn

    6時間ほどして、メール制限解除とDNS逆引きの設定が終わったと連絡があった。

    題名 : Re: Your AWS Inquiry [99999]
    差出人 :Amazon Web Services
    
    Hello nnnn,
    
    Thank you for getting back to us with the requested.
    
    Accordingly, we have configured the reverse DNS record(s) you requested! Your request was mapped for the following:
    
    =======================================================
    Successfully setup mail.domain.com as rDNS for xxx.xxx.xxx.xxx
    =======================================================
    
    Please note that propagation of this update to DNSBL services that Amazon works with may take up to a week.
    
    Email sending limitations have also been removed for any resources for the region your EIP is located in.
    
    Please let us know if you have any questions.
    
    Regards,
    AWS Trust and Safety