Nginx グループの変更

Nginx グループの変更

開発環境では、Apache サイトの一部を Nginx に移行しています。同じグループ ( webgroup) に属する開発者全員が、Web サーバー ユーザー ( ) によって作成されたファイル (ログ ファイルなど) に完全にアクセスできるようにしたいと考えていますwww-data。Web ユーザーが作成したファイルは、通常 が所有するため、www-data:www-dataそのユーザーのプライマリ グループを開発者 ( ) のプライマリ グループと一致するように変更することにしましたwebgroup

グループの変更は完了したようですが、新しく作成されたファイルの所有者は のままですwww-data:www-data。nginx groupconf のディレクティブが表示されないので、nginx ユーザーによって作成/更新されたファイルが適切なグループによって所有されるようにする方法があるかどうか疑問に思っています。

事前に考えていれば、www-dataすべてのユーザーに対してプライマリ グループを作成できたと思いますが、そうしなかったため、後戻りしてすべてのユーザーに触れることは避けたいと思います。これは開発環境であるため、セキュリティはそれほど重要ではありませんが、それでも、全員が root として認証されるか、同様に完全にオープンになることは避けたいと思います。

アップデート

それ以来、以下のようにファイルを更新しようとしましたが、効果はありませんでした。再起動と強制リロードの後でも、nginx.conf新しいファイルが作成されます。www-data:www-data

user www-data webgroup

答え1

ログ ファイルを保存するフォルダーにスティッキー ビットを適用するだけです。nginx は、ログを作成するためにコンパイル時に指定されたグループを常に使用します。構成内のグループ ディレクティブは、実行時にのみ適用されます。

chown -R www-data:webgroup /var/log/nginx && chmod g+s /var/log/nginx

答え2

nginx グループを変更するには再コンパイルが必要です。幸いなことに、これは非常に簡単です。次の簡単な手順に従ってください。

  1. 最新の nginx ソースコードをダウンロード:
    • wget http://nginx.org/download/nginx-1.11.9.tar.gz
  2. 開梱する
    • tar xzvf nginx-1.11.9.tar.gz
  3. ソースディレクトリに移動する
    • cd nginx-1.11.9
  4. nginx -V出力から現在の nginx 構成引数を取得します。

    • nginx -Vサンプル出力:

      --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --user=www-data --group=www-data

  5. 必要なオプションを置き換えて./configureソースルートで起動します

    • ./configure --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --user=apache --group=apache
  6. コマンドが完了するまで待ちます(必要に応じて外部モジュールをダウンロードします)。

    • make && make install

nginx今、あなたは好きなオプションを備えた真新しいものを手に入れました!

関連情報