Nginx configuration for Joomla and Codeigniter inside a subdirectory

The following nginx configuration seems to be inoperative and returns a 404 error when accessing http://example.com/xml_apps/ - however, the Joomla site works fine with the root URL http://example.com

UPDATE It seems that the queries are now being sent to the codeigniter application, as the 404 error comes from the CI application.

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

Do I need some configuration to add for the codeigniter level? for information on the operation of the controller / action.

 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; } } 
+6
source share
3 answers

Regarding setting the CodeIgniter level, edit the application / config / config.php file (also read the comments in config.php)

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

If you need good URLs, please also use the code below.

 $config['index_page'] = ''; 

Regarding Nginx settings, visit the Nginx community - everything is explained very well here.

Edit

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; } 
+1
source

There is nothing wrong with the configuration file, and assuming you are using the latest version of NGINX, I highly recommend that you take a look at the topology of the network card to see if there are 2 or more hops that might cause the problem, because if there is a router, which is located behind the main router of your server, then the HTTP protocol is dropped by the first router. To fix this problem, I suggest you switch to HYPER TERMINAL and use the ip route command for the first router to route the host ip-domain to the rotor, which interferes with the connection.

Hope this solves your problem!

+1
source

Try replacing your location / xml _apps / block with this

 location /xml_apps/ { try_files $uri $uri/ /xml_apps/index.php?$args; } 

And make sure your codeigniter base_url configuration is correct.

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

+1
source

Source: https://habr.com/ru/post/979125/


All Articles