天天看点

从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

继续阅读