Welcome to Centmin Mod Community
Become a Member

Nginx Domains Domain Vhost Conf

Discussion in 'Install & Upgrades or Pre-Install Questions' started by gasak, Jul 2, 2017.

  1. gasak

    gasak New Member

    28
    3
    3
    May 15, 2017
    Ratings:
    +5
    Local Time:
    12:10 AM
    1.13.0
    10.1.23-MariaDB
    Hi Again,

    Just wanna ask regarding vhost domain conf in /usr/local/nginx.conf/conf.d/

    Is there any way that we can edit the pre-compile setting so whenever we add domain to the server the domain.com.conf configuration is as what we want it?

    Since nginx doesn't support htaccess so I need to edit domain.com.conf for every domain to be able to read wordpress permalink. It just awful if doing it for 100 domains hahaha. So is there anyway to do it? Because I need to put another line also beside the permalink into the conf.

    Please advice. Many thanks.
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,191
    6,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,142
    Local Time:
    3:10 AM
    Nginx 1.13.x
    MariaDB 5.5
    Not right now. But centmin.sh menu option 22 wordpress auto install by default enables wordpress permalink support out of the box already.

    @ethanpil has a proposed enhancement at Additions to custom_config.inc for persistent NGINX .conf and something I am definitely looking at in future. Though for wordpress, centmin.sh menu option 22 already does that for you.
     
  3. gasak

    gasak New Member

    28
    3
    3
    May 15, 2017
    Ratings:
    +5
    Local Time:
    12:10 AM
    1.13.0
    10.1.23-MariaDB
    I see. Well, I'm using a cloner for WordPress, so I don't install WordPress from the beginning. That's why I need to still edit the domain.conf.
     
  4. eva2000

    eva2000 Administrator Staff Member

    30,191
    6,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,142
    Local Time:
    3:10 AM
    Nginx 1.13.x
    MariaDB 5.5
    For now if all your vhosts are wordpress, you can mass insert the try_files permalink rule for wordpress if you want. Below only works if your vhost has the default template entry for
    Code (Text):
    #autoindex_localtime on;
    

    as sed replacement uses that line as an anchor for sed replacement/insertion

    backup /usr/local/nginx/conf/conf.d/ to /usr/local/nginx/conf/conf.d-backup1 and then for every vhost config file in /usr/local/nginx/conf/conf.d/ use sed replacement to insert wordpress permalink try_files

    2 commands below
    Code (Text):
    cp -a /usr/local/nginx/conf/conf.d/ /usr/local/nginx/conf/conf.d-backup1
    
    ls /usr/local/nginx/conf/conf.d/ | egrep -vw 'demodomain.com.conf|virtual.conf' | while read v; do sed -i "s|#autoindex_localtime on;|#autoindex_localtime on;\n\n  try_files \$uri \$uri/ /index.php?q=\$uri\&\$args;|"  /usr/local/nginx/conf/conf.d/${v}; done
    

    restart nginx afterwards and test nginx configs
    Code (Text):
    nginx -t
    ngxrestart
    
     
  5. eva2000

    eva2000 Administrator Staff Member

    30,191
    6,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,142
    Local Time:
    3:10 AM
    Nginx 1.13.x
    MariaDB 5.5
    if you need to add a line after the try_files you can try
    Code (Text):
    cp -a /usr/local/nginx/conf/conf.d/ /usr/local/nginx/conf/conf.d-backup1
    ls /usr/local/nginx/conf/conf.d/ | egrep -vw 'demodomain.com.conf|virtual.conf' | while read v; do sed -i "s|#autoindex_localtime on;|#autoindex_localtime on;\n\n  try_files \$uri \$uri/ /index.php?q=\$uri\&\$args;\n\n  include /usr/local/nginx/conf/myinclude-file.conf;|"  /usr/local/nginx/conf/conf.d/${v}; done
    touch /usr/local/nginx/conf/myinclude-file.conf
    

    so you end up with include file at /usr/local/nginx/conf/myinclude-file.conf and add custom lines within that file to be used within main web root /

    example domain nginx vhost's web root / location context afterwards
    Code (Text):
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    # block common exploits, sql injections etc
    #include /usr/local/nginx/conf/block.conf;
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # Shows file listing times as local time
      #autoindex_localtime on;
    
      try_files $uri $uri/ /index.php?q=$uri&$args;
    
      include /usr/local/nginx/conf/myinclude-file.conf; 
    
      # Wordpress Permalinks example
      #try_files $uri $uri/ /index.php?q=$uri&$args;
    
      }
    
     
    Last edited: Jul 2, 2017
  6. gasak

    gasak New Member

    28
    3
    3
    May 15, 2017
    Ratings:
    +5
    Local Time:
    12:10 AM
    1.13.0
    10.1.23-MariaDB
    Can we just put the try_files permalink together with other command line in myinclude-file.conf? So we just include file myinclude-file.conf in domain.conf.

    So it would be like:
    Code:
    # Enables directory listings when index file not found
      #autoindex  on;
    
      # Shows file listing times as local time
      #autoindex_localtime on;
    
      # Enable for vBulletin usage WITHOUT vbSEO installed
      # More example Nginx vhost configurations at
      # http://centminmod.com/nginx_configure.html
      #try_files        $uri $uri/ /index.php;
    
    include /usr/local/nginx/conf/myinclude-file.conf;
    
    }
    While in the myinclude-file.conf is like this:
    Code:
    try_files $uri $uri/ /index.php?q=$request_uri;
    
    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
    access_log off;
    log_not_found off;
    expires 356d;
    
    }
    
    location ~* /(wp-login\.php) {
         include /usr/local/nginx/conf/php.conf;
         auth_basic "Private";
         auth_basic_user_file /usr/local/nginx/conf/htpasswd;
            }
    
    Because I want to add additional those lines inside the domain.conf. Please advice.

    Many thanks.
     
  7. eva2000

    eva2000 Administrator Staff Member

    30,191
    6,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,142
    Local Time:
    3:10 AM
    Nginx 1.13.x
    MariaDB 5.5
    in my example, you can't as the include file is placed within web root / location ONLY
    i.e.
    Code (Text):
    location / {
      include /usr/local/nginx/conf/myinclude-file.conf;
    }
    

    Static file location match already taken care of in
    Code (Text):
    include /usr/local/nginx/conf/staticfiles.conf;
    

    for wp-login.php password, is it same password for all wordpress sites ? if different for each site, then a general single include wouldn't suffice anyway

    of course if you know shell bash scripting you can do sed replacements on other positioned anchors within default templates
     
  8. gasak

    gasak New Member

    28
    3
    3
    May 15, 2017
    Ratings:
    +5
    Local Time:
    12:10 AM
    1.13.0
    10.1.23-MariaDB
    I see I didn't notice the staticfiles.conf. Yes, the password is same for all the WordPress sites. So what is the easy way to implement that to all the domains.conf file?

    Many thanks.
     
  9. eva2000

    eva2000 Administrator Staff Member

    30,191
    6,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,142
    Local Time:
    3:10 AM
    Nginx 1.13.x
    MariaDB 5.5
    you could separately insert a /usr/local/nginx/conf/pre-staticfiles.conf include file above staticfiles.conf include and place the wp-login location match in /usr/local/nginx/conf/pre-staticfiles.conf

    Code (Text):
    cp -a /usr/local/nginx/conf/conf.d/ /usr/local/nginx/conf/conf.d-backup-prestatic
    ls /usr/local/nginx/conf/conf.d/ | egrep -vw 'demodomain.com.conf|virtual.conf' | while read v; do sed -i "s|  include \/usr\/local\/nginx\/conf\/staticfiles.conf;|  include \/usr\/local\/nginx\/conf\/pre-staticfiles.conf;\n  include \/usr\/local\/nginx\/conf\/staticfiles.conf;|"  /usr/local/nginx/conf/conf.d/${v}; done
    touch /usr/local/nginx/conf/pre-staticfiles.conf
    

    Code (Text):
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    # block common exploits, sql injections etc
    #include /usr/local/nginx/conf/block.conf;
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # Shows file listing times as local time
      #autoindex_localtime on;
    
      try_files $uri $uri/ /index.php?q=$uri&$args;
    
      include /usr/local/nginx/conf/myinclude-file.conf;
    
      # Wordpress Permalinks example
      #try_files $uri $uri/ /index.php?q=$uri&$args;
    
      }
    
      include /usr/local/nginx/conf/pre-staticfiles.conf;
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/php.conf;
     
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
     
  10. gasak

    gasak New Member

    28
    3
    3
    May 15, 2017
    Ratings:
    +5
    Local Time:
    12:10 AM
    1.13.0
    10.1.23-MariaDB
    Alright will give it a shot. Thanks a lot @eva2000
     
  11. eva2000

    eva2000 Administrator Staff Member

    30,191
    6,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,142
    Local Time:
    3:10 AM
    Nginx 1.13.x
    MariaDB 5.5
  12. gasak

    gasak New Member

    28
    3
    3
    May 15, 2017
    Ratings:
    +5
    Local Time:
    12:10 AM
    1.13.0
    10.1.23-MariaDB
    Oh ya, another question, when you will release the stable version of 123.09? :D
     
  13. eva2000

    eva2000 Administrator Staff Member

    30,191
    6,788
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,142
    Local Time:
    3:10 AM
    Nginx 1.13.x
    MariaDB 5.5