index.php redirect ngnix

Hi all,



I’m currently encountering a really frustrating issue with Mautic. I have an installation on Ubuntu with Ngnix installed and using serverpilot to manage. The problem I’m facing is when I type the domain, I get 404. When I add index.php to the domain, it works perfectly.



I have followed all of the advice I can find on this forum in regards to redirects in the .conf file, but to no avail.



Does anyone have an Ngnix template they could share? or could someone help me with writing a new one. The ones from here and google didn’t work for me.



Hope you can help!

Hi all,

I’m currently encountering a really frustrating issue with Mautic. I have an installation on Ubuntu with Ngnix installed and using serverpilot to manage. The problem I’m facing is when I type the domain, I get 404. When I add index.php to the domain, it works perfectly.

I have followed all of the advice I can find on this forum in regards to redirects in the .conf file, but to no avail.

Does anyone have an Ngnix template they could share? or could someone help me with writing a new one. The ones from here and google didn’t work for me.

Hope you can help!

Hi Harry,

I had the same and was looking for an solution for ages.
I’m definitely not an expert, but I managed to get rid of that annoying issue by using the following config file (sites-default/default):

[code]##

You should look at the following URL’s in order to grasp a solid understanding

of Nginx configuration files in order to fully unleash the power of Nginx.

https://www.nginx.com/resources/wiki/start/

https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/

https://wiki.debian.org/Nginx/DirectoryStructure

In most cases, administrators will remove this file from sites-enabled/ and

leave it as reference inside of sites-available where it will continue to be

updated by the nginx packaging team.

This file will automatically load configuration files provided by other

applications, such as Drupal or Wordpress. These applications will be made

available underneath a path with that package name, such as /drupal8.

Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.

server {
listen 443 ssl;
root /var/www/mautic;

Mautic Specific
   # For any inbound request to the mautic directory try using mautic index.php to handle the requests before you give up.
   location / {
      try_files $uri  /var/www/mautic/;
   }

    # For any inbound requests that have non-exisiting files with these extentions:
    # Try passing the request to mautic before you give up and throw a 404.
    # This is particularly important in order to get paths like this to work correctly:
    # https://host.domain.tld/mautic/form/generate.js?id=1 (If you look at the Mautic code there is a public route
    # - mautic_form_generateform -  that handles the creation of this "file".)
    #  Normally files like this would be handled by nginx as "physical files", but in this case we want nginx to
    # check with mautic to see if it has what the request is looking for.)
    location ~ /mautic/(.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)){
        # .gif and .js files here are not showing up.
        try_files $uri $uri/ /mautic/index.php?$args;
    }
    ##### End Mautic ###########

   location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }

    location ~ /.ht {
        deny all;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

   # error_page 500 502 503 504 /50x.html;
       location = /50x.html {
    }

    location ~ [^/].php(/|$) {
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
        fastcgi_index            index.php;
        fastcgi_param            PATH_INFO        $fastcgi_script_name;
        fastcgi_param            SCRIPT_FILENAME  $document_root$fastcgi_script_name;  # same path as above
        fastcgi_pass             unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info  ^(.+?.php)(/.*)$;
        include                  /etc/nginx/fastcgi_params;
    }

}

server{
listen 80;
return 301 https://%%%domainurl%%%$request_uri;
}
[/code]

Please note that this is only working if you enabled SSL on your nginx config. I do not know if this code is safe, corrupt or not good at all. I just used it and it worked.

Also dont forget to change the ‘%%%domainurl%%%’ to your domain (or subdomain) and to change the dir of the root url.

Have a nice day!

Rick

Hi Rick,

Sadly this didn’t work for me even with SSL. I do not have a site-available folder in my server. Do you think server pilot may have removed it? Pulling my hair out here…!

Bump… Can anyone help with this? :slight_smile:

Can anyone help?

@harryjwilson it seems a permission issue . how i can check it out ?

@harryjwilson you are missing a module or extension in your server is called a2enmod rewrite

@ninjoan you mean PHP extention?

yes is called extension

@ninjoan indeed