Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joomla with Nginx Rewrite SEF url

I am using Ubuntu 12.04 with NGINX and PHP5-FPM. I've just migrated my Joomla website from Apache to NGINX. But i think rewrite rules are not working well.

All of the SEF links rewrite to the homepage, but in the url bar link seems right.

Example if i click example.com/a/b.html it looks like go to the link in the url bar but homapage is loading.

Thanks for your help.

/etc/nginx/sites-available/example.com file

server {
    listen 80;
    server_name example.com;
    #server_name_in_redirect off;

    #access_log /var/log/nginx/localhost.access_log main;
    #error_log /var/log/nginx/localhost.error_log info;

    root /var/www/example.com/public_html/;
    index index.php index.html index.htm default.html default.htm;
    # Support Clean (aka Search Engine Friendly) URLs
    location / {
            try_files $uri $uri/ /index.php?q=$request_uri;
    }

    # deny running scripts inside writable directories
    location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
            return 403;
            error_page 403 /403_error.html;
    }

    location ~ \.php$ {
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            include fastcgi_params;
            #fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }

    # caching of files 
    location ~* \.(ico|pdf|flv)$ {
            expires 1y;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
            expires 14d;
    }

 }

nginx.conf

user www-data;
worker_processes 8;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
# multi_accept on;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
types_hash_max_size 2048;
server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

gzip_vary on;
# gzip_proxied any;
gzip_comp_level 6;
# gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

#include /etc/nginx/naxsi_core.rules;

##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##

#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;


    ## Block spammers and other unwanted visitors  ##
    include /etc/nginx/blockips.conf;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
   }
like image 372
John Rock Avatar asked Oct 21 '22 17:10

John Rock


1 Answers

Yes - this reply is over 3 years old, but, unfortunately, the same problem exists on the latest version of Joomla when using NGINX...

We had the exact same problem on one of our client's sites. The problem turned out to be related to one of PHP's $_SERVER constants not being set by the NGINX server - and that constant (which is `$_SERVER['PHP_SELF']) is used in many places in Joomla to return the current URL. We have described, in details, the problem and how to fix it, here.

like image 186
itoctopus Avatar answered Oct 27 '22 18:10

itoctopus