Discover Centmin Mod today
Register Now

Custom post-add nginx vhost

Discussion in 'Install & Upgrades or Pre-Install Questions' started by noxonx, Jun 29, 2020.

  1. noxonx

    noxonx New Member

    3
    0
    1
    May 15, 2020
    Ratings:
    +0
    Local Time:
    6:35 AM
    Hi,
    is it possible to run some custom script after creating nginx vhost? I need to set up HTTP basic authentication after each creation and it would be great if I didn't have to run the script manually every time but it could run after executing menu 2.
    Thank you.
     
  2. eva2000

    eva2000 Administrator Staff Member

    44,804
    10,216
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,834
    Local Time:
    2:35 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    If you already have a script and using centmin.sh menu option 2 to create nginx vhosts, you can just script nginx vhost creation using alternative nv command line outlined at
    so enable letsencrypt SSL support one time task
    Code (Text):
    touch /etc/centminmod/custom_config.inc
    echo "LETSENCRYPT_DETECT='y'" >> /etc/centminmod/custom_config.inc
    

    then to create Nginx vhost domain = domain.com you make sure DNS A record for domain.com and www version of domain points to server IP address

    and then just run nv command line changing ftpusername to your desired pure-ftpd virtual ftp username
    Code (Text):
    nv -d domain.com -s lelived -u ftpusername
    

    if you have you own script to run afterwards and you modify to work based on domain name passed via the script, you can script it as such
    Code (Text):
    #!/bin/bash
    nv -d domain.com -s lelived -u ftpusername
    /run/your/script.sh domain.com
    

    Centmin Mod overview of all structures/config files at Centmin Mod Configuration Files - CentminMod.com LEMP Nginx web stack for CentOS so if your script modifies nginx vhost with https you'd want to be modifying /usr/local/nginx/conf/conf.d/domain.com.ssl.conf nginx vhost
     
  3. noxonx

    noxonx New Member

    3
    0
    1
    May 15, 2020
    Ratings:
    +0
    Local Time:
    6:35 AM
    Thanks, that's exactly what I need. I can also use mysqladmin_shell.ssh. All in one custom script.

    Can you write to me how can I check if vhost and mysql db have been successfully created to create a command string?
    Should I check the output or is it better to check the config (/usr/local/nginx/conf/conf.d/newdomain.com.conf) creation for vhost and db existence?

    Thank you.
     
  4. eva2000

    eva2000 Administrator Staff Member

    44,804
    10,216
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,834
    Local Time:
    2:35 PM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    Yup that is the intention so you can script nginx vhost/site setups
    check for newdomain.com.conf or newdomain.com.ssl.conf in /usr/local/nginx/conf/conf.d and /home/nginx/domain/newdomain.com directory existence

    for mysql databases you can use mysqlshow command and checking command exit status via $? variable. When $? variable returns exit status = 0, means database exists and return non-zero value, means database doesn't exist
    Code (Text):
    dbname=mysql
    mysqlshow $dbname >/dev/null 2>&1; echo $?
    0
    

    Code (Text):
    dbname=mysqlnot
    mysqlshow $dbname >/dev/null 2>&1; echo $?
    1