Want to subscribe to topics you're interested in?
Become a Member

Nginx Auto adding custom laravel permalinks on each new vhost creation

Discussion in 'Centmin Mod Insights' started by aditbaco, Nov 9, 2021.

  1. aditbaco

    aditbaco New Member

    Aug 29, 2021
    Local Time:
    3:30 PM
    I'm using latest beta branch Centminmod and mainly for laravel/vue webserver on my cloud servers and it has been a wonderful experience to-date, except for one small thing... Do someone knows how to auto adding custom laravel permalinks inside location block on each new vhost creation via centmin menu #2?

    Because currently only Wordpress permalinks has been auto generated. The reason is that I keep build/rebuilding my vhost for testing purposes and each time I had to manually changing the conf files to use laravel directive, and it became very tedious task todo :

    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;
          # Wordpress Permalinks example
          #try_files $uri $uri/ /index.php?q=$uri&$args;
          # Laravel Permalinks example
          try_files $uri $uri/ /index.php?$query_string;
    I think could pelase include the laravel permalinks directive on future beta release please? @eva2000
    Last edited: Nov 9, 2021
  2. eva2000

    eva2000 Administrator Staff Member

    May 24, 2014
    Brisbane, Australia
    Local Time:
    6:30 PM
    Nginx 1.25.x
    MariaDB 10.x
    Yeah not so easier to customise out of the box but with some thought you can do it. These are old guides which may have changes since but the principle is the same for customising your Nginx vhosts out of the box right now you can do some workarounds outlined in threads below
    you can probably do simple command line sed replacements of files?

    Code (Text):
    sed -i 's|TEXTTOREPLACE|REPLACEDTEXT|' path/to/filename


    Code (Text):
         #try_files $uri $uri/ /index.php?q=$uri&$args;

    Code (Text):
          try_files $uri $uri/ /index.php?$query_string;

    if /usr/local/nginx/conf/conf.d/domain.com.ssl.conf was the name of Nginx vhost file it would just be
    Code (Text):
    sed -i 's|      #try_files $uri $uri/ /index.php?q=$uri&$args;|      try_files $uri $uri/ /index.php?$query_string;|' /usr/local/nginx/conf/conf.d/domain.com.ssl.conf

    the if /usr/local/nginx/conf/conf.d/domain.com.ssl.conf entry would be changed to
    Code (Text):
          try_files $uri $uri/ /index.php?$query_string;try_files $uri $uri/ /index.php?$query_string;

    So if you use /usr/bin/nv command instead of centmin.sh menu option 2 to create new Centmin Mod Nginx vhosts as per https://community.centminmod.com/th...g-nginx-vhost-mysql-users-and-databases.8257/, you can script it all

    To create Centmin Mod Nginx HTTPS Vhost named yourdomain.com with Letsencrypt SSL certificate it would just be 3 commands in a script you can run.
    1. 1st command via nv creates Nginx vhost with HTTPS default and letsencrypt certificate
    2. 2nd command replaces the default Wordpress permalink with Laravel one
    3. 3rd command restarts Nginx for change to take effect :)
    Code (Text):
    nv -d yourdomain.com -s lelived -u YOURFTP_USERNAME
    sed -i 's|      #try_files $uri $uri/ /index.php?q=$uri&$args;|      try_files $uri $uri/ /index.php?$query_string;|' /usr/local/nginx/conf/conf.d/domain.com.ssl.conf