0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WordPress サブドメインにインストール するnginxの設定【ローカル】【マルチサイト】

Posted at

備忘録です。

前提

Ubuntu でMariadb, php-fpm, nginx が動いている

sites-available に設定ファイル(sub.domain.com) を配置、設定済み。( sites-enabled にもシンボリックリンクを貼り、サイトが有効化された状態)

/etc/hosts に、ローカルのループバックアドレス (127.0.9.xなど、localhostとは異なるループバック) に sub.domain.comでアクセスできる様に設定した状態。
(つまり、ローカル (Ubuntu Desktop) からブラウザで http://sub.domain.com/にアクセスすると nginx の "Welcome!" のページ や、index.php に書いた phpinfo(); のレスポンスが返ってくる状態。)

設定ファイルのディレクトリ構造:

├──/etc/nginx
│   ├──conf.d/default.conf
│   ├──global/wordpress-ms-sub-domain.conf
│   ├──sites-available/sub.domain.com
│   └──nginx.conf

以下を追加、あるいは追記

nginx.conf
client_max_body_size 13m;    # php.ini のupload_max_filesize (2M) より大きく設定し、PHPのエラーで捕捉できるようにする
upstream php {
        server unix:/run/php/php8.1-fpm.sock;
}
sites-available/sub.domain.com
location / {
        # デフォルトではないパーマリンクがクエリ文字列を使っても壊れないように、"?$args "の部分を指定。
        try_files $uri $uri/ /index.php?$args;
}

include /etc/nginx/global/wordpress-ms-sub-domain.conf;
global/wordpress-ms-sub-domain.conf

# location にリクエストされたURLに応じた設定を指定。

location = /favicon.ico {
        log_not_found off;    # 見つからなかったファイルについてのエラーをエラーログに残さないようにする
        access_log off;
}

location = /robots.txt {
        allow all;        
        log_not_found off;
        access_log off;
}
        
location ~ \.php$ {    # PHPスクリプトファイルのリクエスト時。
        #注意: php.iniに "cgi.fix_pathinfo = 0; "を設定

        try_files $uri =404;    # URIにPHPスクリプトが実在するかをチェックし、存在しないファイルのリクエストに対して 404 を返す。

        fastcgi_intercept_errors on;    # FastCGI のレスポンスが 300 と 3xx, 4xx, 5xx のコードを解釈し、error_page ディレクティブの処理にリダイレクトする。
                
        fastcgi_pass php;        # FastCGI サーバーのアドレス
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;    # URLに指定された静的ファイルのリクエストには最大期間キャッシュをもつ
        log_not_found off;    # 攻撃者などの無意味なリクエストをログに出さない
}
.bash
cat /etc/nginx/conf.d/default.conf | grep -i 'error_page'
    #error_page  404              /404.html;
    error_page   500 502 503 504  /50x.html;

cat -n /etc/php/8.1/fpm/php.ini | grep -i 'cgi.fix_pathinf'
   800  ; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
   807  cgi.fix_pathinfo=0
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?