从iRedMail 创建web服务学习Nginx
从iRedMail 创建web服务学习Nginx
. ${CONF_DIR}/web_server
Import global variables for web server 以debian系统为例,存储web应用的路径为HTTPD_SERVERROOT(/opt/Daemon user.export HTTPD_USER='HTTPD_GROUP='nginx配置文件在/etc/nginx中,日志在/var/log/nginx中,临时文件在/var/lib/nginx_tmp_client_body中,
# Configuration filesexport 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"
# 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"
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函数为HTTPD_SERVERROOT和HTTPD_DOCUMENTROOT创建目录,如果web server使用的是nginx,则调用nginx.sh,然后运行其中的nginx_config函数,在运行web_server_extra函数。
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函数创建robots.txt文件,默认将主页重定向到webmail。如果使用ROUNDCUBE,设置url为/mail/;如果使用SOGO,设置url为/SOGo/。
web_server_extra() { # Create robots.txt. if [ ! -e ${HTTPD_DOCUMENTROOT}/robots.txt ]; then cat >> ${HTTPD_DOCUMENTROOT}/robots.txt <