天天看點

從iRedMail 建立web服務學習Nginx

. ${CONF_DIR}/web_server

Import global variables for web server

以debian系統為例,存儲web應用的路徑為HTTPD_SERVERROOT(/opt/www),存儲文檔的路徑為HTTPD_DOCUMENTROOT(‘/var/www/html’),守護使用者群組都為’www-data’。

# Daemon user.
export HTTPD_USER='www-data'
export HTTPD_GROUP='www-data'      
從iRedMail 建立web服務學習Nginx

nginx特有設定

nginx配置檔案在/etc/nginx中,日志在/var/log/nginx中,臨時檔案在/var/lib/nginx_tmp_client_body中,

# Configuration files
export HTTPD_CONF_ROOT='/etc/nginx'
# Log directory.
export NGINX_LOG_DIR='/var/log/nginx'
# Directory for storing temporary files holding client request bodies.
export NGINX_CLIENT_BODY_TEMP_PATH='/var/lib/nginx_tmp_client_body'      

配置檔案放置路徑

export HTTPD_CONF_DIR_AVAILABLE_CONF="${HTTPD_CONF_ROOT}/conf-available"
export HTTPD_CONF_DIR_ENABLED_CONF="${HTTPD_CONF_ROOT}/conf-enabled"      
從iRedMail 建立web服務學習Nginx
從iRedMail 建立web服務學習Nginx
# Directory used to store all sites. Note: not loaded by default.
export HTTPD_CONF_DIR_AVAILABLE_SITES="${HTTPD_CONF_ROOT}/sites-available"
# Directory used to store site config files which will be loaded by default.
# Usually we just create a symbol link to file under ${HTTPD_CONF_DIR_AVAILABLE_SITES}
export HTTPD_CONF_DIR_ENABLED_SITES="${HTTPD_CONF_ROOT}/sites-enabled"      
從iRedMail 建立web服務學習Nginx
從iRedMail 建立web服務學習Nginx
export NGINX_CONF="${HTTPD_CONF_ROOT}/nginx.conf"
export NGINX_CONF_SITE_DEFAULT="${HTTPD_CONF_DIR_AVAILABLE_SITES}/00-default.conf"
export NGINX_CONF_SITE_DEFAULT_SSL="${HTTPD_CONF_DIR_AVAILABLE_SITES}/00-default-ssl.conf"
export NGINX_CONF_TMPL_DIR="${HTTPD_CONF_ROOT}/templates"
export NGINX_MIME_TYPES="${HTTPD_CONF_ROOT}/mime.types"      

functions/web_server.sh

web_server_config() {
    # Create required directories
    [ -d ${HTTPD_SERVERROOT} ] || mkdir -p ${HTTPD_SERVERROOT} >> ${INSTALL_LOG} 2>&1
    [ -d ${HTTPD_DOCUMENTROOT} ] || mkdir -p ${HTTPD_DOCUMENTROOT} >> ${INSTALL_LOG} 2>&1
    if [ X"${WEB_SERVER}" == X'NGINX' ]; then
        . ${FUNCTIONS_DIR}/nginx.sh
        check_status_before_run nginx_config
        check_status_before_run web_server_extra
    fi
    if [ X"${IREDMAIL_USE_PHP}" == X'YES' ]; then
        . ${FUNCTIONS_DIR}/php.sh
        check_status_before_run php_config
    fi
    echo 'export status_web_server_config="DONE"' >> ${STATUS_FILE}
}      
web_server_extra() {
    # Create robots.txt.
    if [ ! -e ${HTTPD_DOCUMENTROOT}/robots.txt ]; then
        cat >> ${HTTPD_DOCUMENTROOT}/robots.txt <<EOF
User-agent: *
Disallow: /
EOF
    fi

    # Redirect home page to webmail by default
    if [ ! -e ${HTTPD_DOCUMENTROOT}/index.html ]; then
        if [ X"${USE_ROUNDCUBE}" == X'YES' ]; then
            echo '<html><head><meta HTTP-EQUIV="REFRESH" content="0; url=/mail/"></head></html>' > ${HTTPD_DOCUMENTROOT}/index.html
        elif [ X"${USE_SOGO}" == X'YES' ]; then
            echo '<html><head><meta HTTP-EQUIV="REFRESH" content="0; url=/SOGo/"></head></html>' > ${HTTPD_DOCUMENTROOT}/index.html
        fi
    fi
    # Add alias for web server daemon user
    add_postfix_alias ${HTTPD_USER} ${SYS_USER_ROOT}
    echo 'export status_web_server_extra="DONE"' >> ${STATUS_FILE}
}      

functions/nginx.sh

繼續閱讀