• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Codeigniter's pretty URLs on Plesk

Meletis_Flevarakis

New Pleskian
Hello, im making a site with Codeingiter 2 (php framework) and i want to enable the pretty urls. Since Plesk is using Apache and nginx i've set the option to use nginx for php files and apache for the rest. The problem is with the pretty urls. How to i add this: http://wiki.nginx.org/Codeigniter to my nginx server? or should i use the htaccess?
 
Hi Meletis_Flevarakis,

as you probably know, nginx ignores all htaccess - files ...these files are for apache and not for nginx.

You find the option to add additional rewrite rules and/or directives over the Plesk Control Panel at:

Domains > YOURDOMAIN ( > YOURSUBDOMAIN ) > Webserver - Settings > Additional NGINX directives ( TEXT - Box ):

You could as well manually add your desired additional configuations for nginx directly at:

/var/www/vhosts/system/YOURDOMAIN_OR_YOURSUBDOMAIN.COM/conf/vhost_nginx.conf

and restart nginx afterwards with the command: service nginx restart

Be sure, that you add only code, which isn't already defined in your domain - specific nginx.conf ( or nginx_ip_default.conf ), because the nginx-configuration-checker will deny double entries or misconfigurations. I mention this, because you linked to a site, where the example shows as well server directives, which can't be set in domain - specific configuration - files for nginx.
It might be as well necessary, to add as well htaccess - files for apache, if the framework desires it.
 
Hello, i've tried to add the directives but im geting this error:

Code:
Invalid nginx configuration: nginx: [emerg] duplicate location "/" in /var/www/vhosts/system/pcbuilds.gr/conf/vhost_nginx.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed

The directives im trying to add:

Code:
location / {
   try_files $uri $uri/ /index.php;
   location = /index.php {
     fastcgi_param  SCRIPT_FILENAME /var/www/vhosts/pcbuilds.gr$fastcgi_script_name;
     include        fastcgi_params;
   }
}
location ~ \.php$ {
   return 444;
}
 
...

Be sure, that you add only code, which isn't already defined in your domain - specific nginx.conf ( or nginx_ip_default.conf ), because the nginx-configuration-checker will deny double entries or misconfigurations. I mention this, because you linked to a site, where the example shows as well server directives, which can't be set in domain - specific configuration - files for nginx.
...

... that's why I already mentioned this, Meletis_Flevarakis.

If you already have a "location /" - definition, you can't set the same location again. You have to choose different ways, as described here: http://nginx.org/en/docs/beginners_guide.html
 
Hi Meletis_Flevarakis,

sure... you COULD edit the depending apache or nginx - files manually, but be aware that Plesk might override them, when the system is updated/upgraded/patched and as well, if Plesk recreates configuration files, when you change/edit/add something in the webserver - settings, but the configuration-checker will always point to misconfigurations, either if you use the Plesk Control Panel, or if you choose to manually modify your files, when you restart your apache and/or nginx service.
 
Hi Meletis_Flevarakis,

well, there is no "best" way for nginx - location definitions. This always depends on your very own configuration and nobody can guess for example, where you installed CI.

A very simple way is always using subfolders in your document root for a domain / subdomain, because then additional location defintions could be defined like this:
Code:
if (!-f $request_filename){
    set $rule_0 1;
}
if ($rule_0 = "1"){
    rewrite ^/(.*)$ /YOUR_SPECIFIC_SUBFOLDER/index.php/$1 last;
}
 
UFHH01's answer helped.
Paste the following in Plesk under the

Your Domain.com - >Apache & nginx Settings -> Additional nginx directives

Code:
if (!-f $request_filename){
   set $rule_0 1;
}
if ($rule_0 = "1"){
   rewrite ^/(.*)$ /YOUR_SPECIFIC_SUBFOLDER/index.php/$1 last;
}
 
Back
Top