Skate in Mars

Aller au contenu | Aller au menu | Aller à la recherche

vendredi 8 février 2008

Dis vert !

Bon voila, j'ai plein d'idées de billet hyper interressants, mais aucune motive, donc je vais faire un petit billet de lien pour donner l'illusion que ce blog est encore actif.
Hop hop trève de discussions :

Voila, si vous vous attendiez à plus d'explications, bah, tant pis.

jeudi 1 novembre 2007

phpMyAdmin and HTTPS on nginx

Okay, this is just a really small post to resurrect the blog, but this could be useful as I lost some time looking for an answer to that problem, and that's why I'll write this one in english :)


If you're trying to set up a phpMyAdmin with nginx and an SSL vhost and fastcgi, you should have seen an issue with the urls produced by phpMyAdmin.

phpMyAdmin does not detect that the pages are served through an HTTPS connection and only detect the used port. It will result in urls like "http://phpmyadmin.mydomain.com:443/"

Trying to follow theses urls will result with nginx sending a 400 error like "The plain HTTP request was sent to HTTPS port"


I tried to dig in the code to see how phpMyAdmin was doing to detect HTTPS setups, and one of the few ways was looking for a $_SERVER['HTTPS'] variable set to 'on'. But in fact I didn't have to look for this as alxkbs already provided the (quite simple) solution on his russian blog : http://alexkbs.livejournal.com/208480.html

So, to have working HTTPS setup, you only have to add to snippet in your nginx vhost with your other fastcgi parameters :

fastcgi_param HTTPS on;

phpMyAdmin will then properly detect the SSL setup and produce clean, working urls.

Hope this can save some time for people running into the same problem !

lundi 3 septembre 2007

Setup CodeIgniter on Nginx server with fastcgi

(Yes, I decided to write a post in english, as this might be useful for a lot of people).

Today I lost some time trying to set up code igniter with fastcgi and an nginx server. Google wasn't really helpful but I found a part of the answer on this thread in the ci forums but I had to dig through the nginx and ci config files. Here is what I have finally done to make this work.

First you have to set up a rewrite rule if you want ci's nice urls (example.com/controller/method/param). I assume you use different vhost files with a specific server directive in each. So, in your nginx config file, configure your server_name, logs, and listen directives as usual, then use this for the / location :

  location /
  {
    index index.php;
    root  /path/to/your/ci/directory;

    if ($request_filename !~ (js|css|images|robots\.txt|index\.php.*) ) {
      rewrite ^/(.*)$ /index.php/$1 last;
    }
  }


Replace the root param with your web directory, which will contain your static files. You can modify the $request_filename regexp to exclude files and directories (if you have a files/ directory for example) from the rewrite.
Note the ^/ in the regexp part from the rewrite, this will avoid getting urls like /index.php//method. I don't know if this is mandatory as the user won't see this rewrite.

Then, add this :

  location ~ /index.php/
  {
    include /usr/local/nginx/conf/fastcgi.conf;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /path/to/your/index.php;
    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;
    fastcgi_pass   127.0.0.1:9000;
  }


This will redirect queries to /index.php/* to your fastcgi thread. I had to use the location directive because nginx doesn't allow to change fastcgi_params within a rewrite directive.
Some fastcgi_params could not be necessary for you depending on your fastcgi.conf. Of course you have to adapt the include and fastcgi_pass directives for your setup. This website : http://www.alrond.com/en/2007/jan/25/performance-test-of-6-leading-frameworks/ will provide additional informations on php+fastcgi if you need. You can also see the nginx documentation.
Note that the SCRIPT_FILENAME parameter points directly to your index.php file, not to $fastcgi_script_name as usual.

You can now test this setup, which should work... Err, not really. You can see your default controller but your queries to other methods arn't working. CI does not see your request, so you'll have to change his configuration.

Edit the (system/)application/config/config.php file and look for the $config['uri_protocol'] config option. Change it to :
$config['uri_protocol']  = "REQUEST_URI";
Now CI can retrieve the full URI and your application should work fine.

I hope this can be useful for someone :)