Browse Source

Update vhost.sh

lj2007331 8 years ago
parent
commit
d249a2e392
4 changed files with 20 additions and 109 deletions
  1. 5 5
      include/upgrade_web.sh
  2. 1 1
      install.sh
  3. 1 1
      versions.txt
  4. 13 102
      vhost.sh

+ 5 - 5
include/upgrade_web.sh

@@ -48,7 +48,7 @@ if [ -e "nginx-$NEW_Nginx_version.tar.gz" ];then
     ./configure $nginx_configure_arguments
     make -j ${THREAD}
     if [ -f "objs/nginx" ];then
-        /bin/mv $nginx_install_dir/sbin/nginx $nginx_install_dir/sbin/nginx$(date +%m%d)
+        /bin/mv $nginx_install_dir/sbin/nginx{,`date +%m%d`}
         /bin/cp objs/nginx $nginx_install_dir/sbin/nginx
         kill -USR2 `cat /var/run/nginx.pid`
         sleep 1
@@ -102,9 +102,9 @@ if [ -e "tengine-$NEW_Tengine_version.tar.gz" ];then
     ./configure $tengine_configure_arguments
     make -j ${THREAD}
     if [ -f "objs/nginx" ];then
-        /bin/mv $tengine_install_dir/sbin/nginx $tengine_install_dir/sbin/nginx$(date +%m%d)
-        /bin/mv $tengine_install_dir/sbin/dso_tool $tengine_install_dir/sbin/dso_tool$(date +%m%d)
-        /bin/mv $tengine_install_dir/modules $tengine_install_dir/modules$(date +%m%d)
+        /bin/mv $tengine_install_dir/sbin/nginx{,`date +%m%d`}
+        /bin/mv $tengine_install_dir/sbin/dso_tool{,`date +%m%d`}
+        /bin/mv $tengine_install_dir/modules{,`date +%m%d`}
         /bin/cp objs/nginx $tengine_install_dir/sbin/nginx
         /bin/cp objs/dso_tool $tengine_install_dir/sbin/dso_tool
         chmod +x $tengine_install_dir/sbin/*
@@ -164,7 +164,7 @@ if [ -e "openresty-$NEW_OpenResty_version.tar.gz" ];then
     ./configure --prefix=$openresty_install_dir --user=$run_user --group=$run_user --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-openssl=../openssl-$openssl_version --with-pcre=../pcre-$pcre_version --with-pcre-jit $malloc_module
     make -j ${THREAD}
     if [ -f "build/nginx-$openresty_version_tmp/objs/nginx" ];then
-        /bin/mv $openresty_install_dir/nginx/sbin/nginx $openresty_install_dir/nginx/sbin/nginx$(date +%m%d)
+        /bin/mv $openresty_install_dir/nginx/sbin/nginx{,`date +%m%d`}
         make install
         kill -USR2 `cat /var/run/nginx.pid`
         sleep 1

+ 1 - 1
install.sh

@@ -75,7 +75,7 @@ while :; do echo
                 else
                     [ "$Nginx_version" != '4' -a -e "$nginx_install_dir/sbin/nginx" ] && { echo "${CWARNING}Nginx already installed! ${CEND}"; Nginx_version=Other; }
                     [ "$Nginx_version" != '4' -a -e "$tengine_install_dir/sbin/nginx" ] && { echo "${CWARNING}Tengine already installed! ${CEND}"; Nginx_version=Other; }
-                    [ "$Nginx_version" != '4' -a -e "$openresty_install_dir/sbin/nginx" ] && { echo "${CWARNING}OpenResty already installed! ${CEND}"; Nginx_version=Other; }
+                    [ "$Nginx_version" != '4' -a -e "$openresty_install_dir/nginx/sbin/nginx" ] && { echo "${CWARNING}OpenResty already installed! ${CEND}"; Nginx_version=Other; }
                     break
                 fi
             done

+ 1 - 1
versions.txt

@@ -67,7 +67,7 @@ memcached_pecl_version=2.2.0
 memcache_pecl_version=3.0.8
 
 # phpMyadmin
-phpMyAdmin_version=4.4.15.7
+phpMyAdmin_version=4.4.15.8
 
 # jemalloc
 jemalloc_version=4.2.1

+ 13 - 102
vhost.sh

@@ -312,13 +312,22 @@ if [ "$moredomainame_yn" == 'y' ]; then
 fi
 
 if [ "$nginx_ssl_yn" == 'y' ]; then
+    while :; do echo
+        read -p "Do you want to redirect all HTTP requests to HTTPS? [y/n]: " https_yn
+        if [[ ! $https_yn =~ ^[y,n]$ ]];then
+            echo "${CWARNING}input error! Please only input 'y' or 'n'${CEND}"
+        else
+            break
+        fi
+    done
+
     if [[ "$($web_install_dir/sbin/nginx -V 2>&1 | grep -Eo 'with-http_v2_module')" = 'with-http_v2_module' ]]; then
       LISTENOPT='443 ssl http2'
     else
       LISTENOPT='443 ssl spdy'
     fi
     Create_SSL
-    Nginx_conf=$(echo -e "listen $LISTENOPT;\nssl_certificate $PATH_SSL/$domain.crt;\nssl_certificate_key $PATH_SSL/$domain.key;\nssl_protocols TLSv1 TLSv1.1 TLSv1.2;\nssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;\nssl_prefer_server_ciphers on;\nssl_session_timeout 10m;\nssl_session_cache builtin:1000 shared:SSL:10m;\nssl_buffer_size 1400;\nadd_header Strict-Transport-Security max-age=15768000;\nssl_stapling on;\nssl_stapling_verify on;\n")
+    Nginx_conf=$(echo -e "listen 80;\nlisten $LISTENOPT;\nssl_certificate $PATH_SSL/$domain.crt;\nssl_certificate_key $PATH_SSL/$domain.key;\nssl_protocols TLSv1 TLSv1.1 TLSv1.2;\nssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;\nssl_prefer_server_ciphers on;\nssl_session_timeout 10m;\nssl_session_cache builtin:1000 shared:SSL:10m;\nssl_buffer_size 1400;\nadd_header Strict-Transport-Security max-age=15768000;\nssl_stapling on;\nssl_stapling_verify on;\n")
     Apache_SSL=$(echo -e "SSLEngine on\n    SSLCertificateFile \"$PATH_SSL/$domain.crt\"\n    SSLCertificateKeyFile \"$PATH_SSL/$domain.key\"")
 elif [ "$apache_ssl_yn" == 'y' ]; then
     Create_SSL
@@ -448,36 +457,7 @@ $NGX_CONF
 }
 EOF
 
-if [ "$nginx_ssl_yn" == 'y' -a "$redirect_yn" == 'y' ];then
-cat >> $web_install_dir/conf/vhost/$domain.conf << EOF
-server {
-listen 80;
-server_name $domain$moredomainame;
-rewrite ^/(.*) https://$domain/\$1 permanent;
-}
-EOF
-elif [ "$nginx_ssl_yn" == 'y' ];then
-cat >> $web_install_dir/conf/vhost/$domain.conf << EOF
-server {
-listen 80;
-server_name $domain$moredomainame;
-$N_log
-index index.html index.htm index.jsp;
-root $vhostdir;
-$Nginx_redirect
-$anti_hotlinking
-location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
-    expires 30d;
-    access_log off;
-    }
-location ~ .*\.(js|css)?$ {
-    expires 7d;
-    access_log off;
-    }
-$NGX_CONF
-}
-EOF
-fi
+[ "$https_yn" == 'y' ] && sed -i "s@^root.*;@&\nif (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" $web_install_dir/conf/vhost/$domain.conf
 
 cat > $tomcat_install_dir/conf/vhost/$domain.xml << EOF
 <Host name="$domain" appBase="webapps" unpackWARs="true" autoDeploy="true"> $Tomcat_Domain_alias
@@ -564,37 +544,7 @@ location ~ .*\.(js|css)?$ {
 }
 EOF
 
-if [ "$nginx_ssl_yn" == 'y' -a "$redirect_yn" == 'y' ];then
-cat >> $web_install_dir/conf/vhost/$domain.conf << EOF
-server {
-listen 80;
-server_name $domain$moredomainame;
-rewrite ^/(.*) https://$domain/\$1 permanent;
-}
-EOF
-elif [ "$nginx_ssl_yn" == 'y' ];then
-cat >> $web_install_dir/conf/vhost/$domain.conf << EOF
-server {
-listen 80;
-server_name $domain$moredomainame;
-$N_log
-index index.html index.htm index.php;
-include $web_install_dir/conf/rewrite/$rewrite.conf;
-root $vhostdir;
-$Nginx_redirect
-$anti_hotlinking
-$NGX_CONF
-location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
-    expires 30d;
-    access_log off;
-    }
-location ~ .*\.(js|css)?$ {
-    expires 7d;
-    access_log off;
-    }
-}
-EOF
-fi
+[ "$https_yn" == 'y' ] && sed -i "s@^root.*;@&\nif (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" $web_install_dir/conf/vhost/$domain.conf
 
 echo
 $web_install_dir/sbin/nginx -t
@@ -737,46 +687,7 @@ location ~ .*\.(js|css)?$ {
 }
 EOF
 
-if [ "$nginx_ssl_yn" == 'y' -a "$redirect_yn" == 'y' ];then
-cat >> $web_install_dir/conf/vhost/$domain.conf << EOF
-server {
-listen 80;
-server_name $domain$moredomainame;
-rewrite ^/(.*) https://$domain/\$1 permanent;
-}
-EOF
-elif [ "$nginx_ssl_yn" == 'y' ];then
-cat >> $web_install_dir/conf/vhost/$domain.conf << EOF
-server {
-listen 80;
-server_name $domain$moredomainame;
-$N_log
-index index.html index.htm index.php;
-root $vhostdir;
-$Nginx_redirect
-$anti_hotlinking
-location / {
-    try_files \$uri @apache;
-    }
-location @apache {
-    proxy_pass http://127.0.0.1:88;
-    include proxy.conf;
-    }
-location ~ .*\.(php|php5|cgi|pl)?$ {
-    proxy_pass http://127.0.0.1:88;
-    include proxy.conf;
-    }
-location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
-    expires 30d;
-    access_log off;
-    }
-location ~ .*\.(js|css)?$ {
-    expires 7d;
-    access_log off;
-    }
-}
-EOF
-fi
+[ "$https_yn" == 'y' ] && sed -i "s@^root.*;@&\nif (\$ssl_protocol = \"\") { return 301 https://\$host\$request_uri; }@" $web_install_dir/conf/vhost/$domain.conf
 
 echo
 $web_install_dir/sbin/nginx -t