#!/bin/bash #################################################################################################### #### author: SlickStack ############################################################################ #### link: https://slickstack.io ################################################################### #### mirror: https://mirrors.slickstack.io/bash/ss-perms-nginx-config.txt ########################## #### path: /var/www/ss-perms-nginx-config ########################################################## #### destination: n/a (not a boilerplate) ########################################################## #### purpose: Resets file and user permissions for Nginx module configuration files ################ #### module version: Nginx 1.18.x ################################################################## #### sourced by: ss-perms, ss-install-nginx ######################################################## #################################################################################################### ## source ss-config ## source /var/www/ss-config ## source ss-functions ## source /var/www/ss-functions ## BELOW THIS RELIES ON SS-CONFIG AND SS-FUNCTIONS #################################################################################################### #### TABLE OF CONTENTS (SS-Perms-Nginx-Config) ##################################################### #################################################################################################### ## this is a brief summary of the different code snippets you will find in this script ## ## each section should be commented so you understand what is being accomplished ## ## A. Touch Timestamp File ## B. Message (Begin Script) ## C. Reset Permissions (Nginx Config) #################################################################################################### #### A. SS-Perms-Nginx-Config: Touch Timestamp File ################################################ #################################################################################################### ## this is a dummy timestamp file that will remember the last time this script was run ## ## it can be useful for developer reference and is sometimes used by SlickStack ## ss_touch "${TIMESTAMP_SS_PERMS_NGINX_CONFIG}" #################################################################################################### #### B. SS-Perms-Nginx-Config: Message (Begin Script) ############################################## #################################################################################################### ## this is a simple message that announces to the shell the purpose of this bash script ## ## it will only be seen by sudo users who manually run this script in the shell ## ss_echo "${COLOR_INFO}Running ss-perms-nginx-config... ${COLOR_RESET}" #################################################################################################### #### C. SS-Perms-Nginx-Config: Reset Permissions (Nginx Config) #################################### #################################################################################################### ## although all permissions are reset in ss-perms we do it on per-module basis as well ## ## this ensures correct permissions in case this script is run individually etc ## ## create directories if not exist ## ss_mkdir /var/www/cache/nginx ss_mkdir /var/www/html ss_mkdir /var/www/logs ss_mkdir /var/www/meta ss_mkdir /var/www/sites ss_mkdir /var/www/sites/includes ## create htpasswd file if not exists ## ss_touch /var/www/meta/.htpasswd ## chown dirs ## chown www-data:www-data /var/www/cache/nginx ## must be www-data:www-data chown "${SFTP_USER}":slickstack /var/www/html ## must be SFTP_USER:slickstack chown www-data:www-data /var/www/logs ## must be www-data:www-data chown www-data:www-data /var/www/meta ## must be www-data:www-data ## chown files ## chown root:root /etc/nginx/fastcgi.conf chown root:root /etc/nginx/nginx.conf chown root:root /var/www/sites/* chown root:root /var/www/sites/includes/ chown www-data:www-data /var/www/meta/.htpasswd ## must be www-data:www-data ## chmod dirs ## chmod 0755 /var/www/cache/nginx ## 0755 seems enough chmod 0775 /var/www/html ## must be 0775 (0755 not enough) chmod 0775 /var/www/logs ## 0755 should also work chmod 0775 /var/www/meta ## 0755 should also work ## chmod files ## chmod 0644 /var/www/meta/.htpasswd ## 0644 seems enough ## create log files if not exist ## if [ ! -f "/var/www/logs/nginx-error.log" ]; then ss_touch "/var/www/logs/nginx-error.log"; fi if [ ! -f "/var/www/logs/nginx-access.log" ]; then ss_touch "/var/www/logs/nginx-access.log"; fi ## reset permissions ## chown www-data:www-data /var/www/logs/nginx*.log chmod 0644 /var/www/logs/nginx*.log ## 0755 should also work #################################################################################################### #### SlickStack: Reset Permissions (SlickStack Scripts) ############################################ #################################################################################################### ## we include this permissions reset in all cron jobs and bash scripts for redundancy ## ## chmod 0700 means only the root/sudo users can execute any SlickStack scripts ## ## THIS SNIPPET DOES NOT RELY ON SS-CONFIG OR SS-FUNCTIONS ## SNIPPET: ss bash scripts, ss cron jobs ## UPDATED: 02JUL2022 chown root:root /var/www/ss* ## must be root:root chown root:root /var/www/crons/*cron* ## must be root:root chown root:root /var/www/crons/custom/*cron* ## must be root:root chmod 0700 /var/www/ss* ## 0700 means only root/sudo can execute chmod 0700 /var/www/crons/*cron* ## 0700 means only root/sudo can execute chmod 0700 /var/www/crons/custom/*cron* ## 0700 means only root/sudo can execute #################################################################################################### #### SlickStack: External References Used To Improve This Script (Thanks, Interwebz) ############### #################################################################################################### ## Ref: https://stackoverflow.com/questions/41736236/nginx-configuration-permissions-and-ownership ## SS_EOF