Nginx, URL rewrite and static files

Need help installing Joomla! 3.x? For all Joomla! 3.x installation issues please use this forum. Note: Users creating new sites can use either version 2.5 or 3.x. Please consider the availability of third-party templates and extensions when deciding which Joomla version to use.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
j0hny
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Dec 29, 2017 2:36 pm

Nginx, URL rewrite and static files

Postby j0hny » Fri Dec 29, 2017 2:59 pm

Hello everyone,

I'm currently attempting to migrate my clients joomla-based web from third party hosting provider to my VPS. It is a Debian 8 machine running nginx, php-fpm with PHP 7.0 and mariadb 10.1.23.

EDIT: I forgot to mention Joomla version - it is the current version 3.8.3

I have managed to make everything work, apart from the search engine friendly (SEF) URLs.

If I turn SEF URLs off, everything works fine. If I turn it on without the "Use URL rewriting" option (which is the setting the site had before migrating), only homepage works, every other page results in 404. If I turn both options on, all pages work except when I try to access articles from homepage - in that case, the page itselfs open, but no CSS, images or other static files work, because they have the name of the article category prepended to their urls like this:

http://joomlasite.example/16-main-page/ ... s/Logo.jpg

instead of:

http://joomlasite.example/images/banners/Logo.jpg

I have noticed that all the articles actually have this URL:

http://joomlasite.example/%category%/%article%

but when I remove the %category% part, the URL still works and static files are loaded fine. I have no idea why the category gets prepended to the URL of static files.

Here is my nginx site conf (with sensitive info removed), any help would be much appreciated:

Code: Select all

server {                                                                                                           
    listen 80;                                                                                                     
                                                                                                                   
    root /srv/http/*****/site/;                                                                             
    index index.php index.html;                                                                                     
                                                                                                                   
    server_name *****                                                                                         
                                                                                                                   
    location ~ /.well-known {                                                                                       
        allow all;                                                                                                 
    }                                                                                                               
                                                                                                                   
    location / {                                                                                                   
        try_files $uri $uri/ index.php?$args;                                                                       
    }                                                                                                               
                                                                                                                   
    include common_params;                                                                                         
                                                                                                                   
    location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
        return 403;
        error_page 403 /403_error.html;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
        fastcgi_pass unix:/var/run/php7.0-fpm-*****.sock;
        fastcgi_index $document_root/index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        fastcgi_param PATH_TRANSLATED $document_root/$fastcgi_path_info;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include fastcgi_params;
    }
}
Last edited by Per Yngve Berg on Fri Dec 29, 2017 7:53 pm, edited 1 time in total.
Reason: Added code tags

gws
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 3031
Joined: Tue Aug 23, 2005 1:56 pm
Location: Kent / Sussex / Surrey border UK
Contact:

Re: Nginx, URL rewrite and static files

Postby gws » Fri Dec 29, 2017 6:19 pm

I believe you have to convert the htaccess file to work on nginx but I am not an expert with nginx.
https://stackoverflow.com/questions/357 ... e-in-nginx

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 23941
Joined: Mon Oct 27, 2008 9:27 pm
Location: Akershus, Norway

Re: Nginx, URL rewrite and static files

Postby Per Yngve Berg » Fri Dec 29, 2017 7:55 pm


j0hny
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Fri Dec 29, 2017 2:36 pm

Re: Nginx, URL rewrite and static files

Postby j0hny » Thu Jan 04, 2018 9:04 am

Hi,

I'm sorry for the silence, had to get away from the computer for the new year's.

Thank you both for answering, but unfortunately, as you can see in the original post, my nginx config file already includes everything from the nginx joomla documentation (which essentialy is converting htaccess file to nginx). I am not exactly a newbie with nginx, I run dozens of sites successfully with URL rewriting. This is just my first joomla installation.

Does anyone have any other ideas?

Thanks!

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 23941
Joined: Mon Oct 27, 2008 9:27 pm
Location: Akershus, Norway

Re: Nginx, URL rewrite and static files

Postby Per Yngve Berg » Fri Jan 05, 2018 5:57 pm

I haven't used Nginx.

SEF without rewrite (with index.php in the url) will work without any rewrite rules, so it's clear that you have errors in your current rules.


Return to “Installation Joomla! 3.x”

Who is online

Users browsing this forum: MarkRidsdale and 6 guests