Get the most out of your Centmin Mod LEMP stack
Become a Member

How to make any custom script work on centminmod : problem with nginx rewrite rules

Discussion in 'Other Web Apps usage' started by yojimbo45, Nov 22, 2021.

  1. yojimbo45

    yojimbo45 New Member

    6
    1
    3
    Jan 10, 2020
    Ratings:
    +3
    Local Time:
    2:19 PM
    Hello, i use centminmod since 2 years but every time u have to use custom script from some code market seller, I have to put them inside a very slow shared hosting with Cpanel because it works only there. why? Everybody use apache and not nginx.

    Please can someone explain to me the methodology to convert for example this apache code to Nginx :

    Code:
    # BEGIN Spark
    Options -Indexes -MultiViews +FollowSymLinks
    AddDefaultCharset UTF-8
    
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$  /$1 [L,R=301]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [QSA,L]
    </IfModule>
    
    <IfModule mod_deflate.c>
    <FilesMatch "\.(html|php|txt|xml|js|css|ttf|otf|ico|json|svg|)$">
    SetOutputFilter DEFLATE
    </FilesMatch>
    </IfModule>
    # END Spark
    

    is this nginx code correct ?


    Code:
    # Most installations will have a default fastcgi_params file setup that you can just include as shown above. Some configurations don’t include the SCRIPT_FILENAME parameter. You must ensure you include this parameter otherwise you might end up with a No input file specified error from the fastcgi process. This can be done directly in the location block or simply added to the fastcgi_params file. Either way it looks like this:
    # fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    
    server {
        listen       80;
        server_name  www.mysite.com mysite.com;
        root         /path/www.mysite.com/public_html;
    
        try_files $uri /index.php;
    
        # this will only pass index.php to the fastcgi process which is generally safer but
        # assumes the whole site is run via Slim.
        location /index.php {
            fastcgi_connect_timeout 3s;     # default of 60s is just too long
            fastcgi_read_timeout 10s;       # default of 60s is just too long
            include fastcgi_params;
            fastcgi_pass 127.0.0.1:9000;    # assumes you are running php-fpm locally on port 9000
        }
    }
    
     
  2. eva2000

    eva2000 Administrator Staff Member

    47,501
    10,779
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,752
    Local Time:
    5:19 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    Yeah using Nginx is dependent on web scripts actually supporting or providing equivalent Nginx rules as Nginx doesn't support modrewrite or .htaccess like Apache does.

    One thing Centmin Mod Nginx already includes a php.conf include file in nginx vhost which handles most location *.php context matches - see https://community.centminmod.com/th...work-differently-in-centmin.19780/#post-84004. So differs even from regular non-Centmin Mod Nginx/PHP-FPM.

    Have you checked out these guides ?
    If you require .htaccess modrewrite, then usually some variant of Nginx try_files directive is all you need. But best to ask the web script's developer/author if they have Nginx rules and ask on their support forums or community discussions. These days a lot more folks use Nginx so there's bound to be someone using your web script with Nginx.