更改 Nginx 群組

更改 Nginx 群組

在我們的開發環境中,我正在將一些 Apache 網站遷移到 Nginx。我想要做的是確保屬於同一組 ( webgroup) 的開發人員能夠完全存取由 Web 伺服器使用者 ( www-data) 建立的檔案(例如日誌檔案)。 Web 使用者建立的檔案通常由擁有者擁有,www-data:www-data因此我想我應該更改該使用者的主要群組以符合開發人員的群組 ( webgroup)。

群組變更似乎已完成,但新建立的檔案仍歸www-data:www-data.我沒有看到groupnginx conf 的指令,所以我想知道是否有任何方法可以確保 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 群組需要重新編譯。幸運的是,它就像 123 一樣簡單。

  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您喜歡的選項!

相關內容