Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx config for Joomla & Codeigniter inside a sub directory

The following nginx configuration seems not working and returns a 404 error when accessing the http://example.com/xml_apps/- however the joomla website works fine from the root url http://example.com

UPDATE It looks like the requests are now sending to codeigniter app as the 404 error is coming from CI app.

http://example.com/xml_apps/index.php/xmlengine/jmprovince?category=1&count=10

Do we need some sort of config to add for codeigniter level? to get the about controller/action working.

server {
    listen   80;
    root /home/ubuntu/websites/example.com/public_html;
    index index.html index.htm index.php;
    server_name example.com;
location / {
    try_files $uri $uri/ /index.php;
}
location /xml_apps/ {
    if ($request_uri ~ "^system.*"){
        rewrite ^/xml_apps/(.*)$ /xml_apps/index.php?/$1 last;
    }
    if (!-e $request_filename){
        rewrite ^/xml_apps/(.*)$ /xml_apps/index.php?/$1 last;
    }
}
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_hide_header X-Powered-By;
    fastcgi_param  REQUEST_URI      $request_uri;
    fastcgi_param  QUERY_STRING     $query_string;
    fastcgi_param  REQUEST_METHOD   $request_method;
    fastcgi_param  CONTENT_TYPE     $content_type;
    fastcgi_param  CONTENT_LENGTH   $content_length;
}
}
like image 428
randika Avatar asked Dec 04 '14 17:12

randika


2 Answers

As for CodeIgniter level setting, do edit application/config/config.php file (read comments in config.php as well)

$config['base_url'] = 'http://example.com/xml_apps';

If you want nice urls please apply code below as well

$config['index_page'] = '';

As for Nginx settings please visit Nginx community - it is all explained there very nicely.

Edit

do change nginx settings

# removes access to "system" folder, also allows a "System.php" controller
if ($request_uri ~* ^/system)
{
    rewrite ^/(.*)$ /index.php?/$1 last;
    break;
}

# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename)
{
    rewrite ^/(.*)$ /index.php?/$1 last;
    break;
}
like image 193
Kyslik Avatar answered Nov 07 '22 18:11

Kyslik


Nothing is wrong with the config file, and assuming that you are using the latest version of NGINX, I highly suggest that you look at your network map topology to see if their are 2 or more hops that may be causing the problem, because if there is a router that is behind the main router of your server then the HTTP protocol is dropped by the first router. In order to fix this problem, I suggest that you hop onto HYPER TERMINAL and use the ip route command for the first router, to route the ip domain of the host to the rotuer that is interfering with the connection.

Hopefully this solves your problem!

like image 1
dumbgamergirl Avatar answered Nov 07 '22 19:11

dumbgamergirl