• Serveurs
  • [Problème] Nginx ne prend pas en compte l'utf-8

Bonjour à tous,

Après avoir suivi le tuto pour la rutorrent/cakebox, j'ai souhaité mettre en place mon site web.

Celui ci est codé en php, avec de l'url rewriting (qui marchait sur mon mutualisé.)

J'ai essayé d'adapté les différents fichiers de conf d'nginx, en fonction de mes besoins.

Description :
- Rutorrent : marche impecable avec le sous domaine rutorrent.mondomaine.fr + authentification
- Cakebox : erreur 502. (le dns a été mis en place correctement)
- Site web : www.mondomaine.fr marche, il n'y d'authentification, juste le problème d'url rewriting, et de charset ()


Les fichiers de config situés dans /etc/nginx/sites-enabled

Rutorrent :
server {
    listen 80;
    listen 443;
    server_name rutorrent.mondomaine.fr;

    charset UTF-8;
    index index.html index.htm index.php;
    client_max_body_size 10M;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    access_log /var/log/nginx/rutorrent-access.log combined;
    error_log /var/log/nginx/rutorrent-error.log error;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html { root /usr/share/nginx/html; }

    auth_basic "seedbox";
    auth_basic_user_file "/etc/nginx/passwd/rutorrent_passwd";

    location = /favicon.ico {
        access_log off;
        log_not_found off;
    }

    ## début config rutorrent ##

    location ^~ / {
        root /var/www/rutorrent;
        include /etc/nginx/conf.d/php;
        include /etc/nginx/conf.d/cache;

        location ~ /\.svn {
                deny all;
        }

        location ~ /\.ht {
                deny all;
        }
    }

    location ^~ /rutorrent/conf/ {
        deny all;
    }

    location ^~ /rutorrent/share/ {
        deny all;
    }

    location /SQDZ {
        include scgi_params;
        scgi_pass 127.0.0.1:5005;
        auth_basic "seedbox";
        auth_basic_user_file "/etc/nginx/passwd/rutorrent_passwd_sqdz";
    }
    ## fin config rutorrent ##

}
Cakebox :
server {
    listen 80;
    server_name cakebox.mondomaine.fr; # sous domaine obligatoire

    root /var/www/cakebox/public;
    index index.php;

    auth_basic "seedbox";
    auth_basic_user_file "/etc/nginx/passwd/rutorrent_passwd";

    charset utf-8;
    include /etc/nginx/conf.d/cache;

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

    location = / {
        try_files @site @site;
    }

    location / {
        try_files $uri $uri/ @site;
    }

    location /sqdz/ {
        alias /home/sqdz/torrents/;
        add_header Content-Disposition "attachment";
        satisfy any;
        allow all;
    }

    location @site {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        fastcgi_param APPLICATION_ENV production;

        ## uncomment when running via https
        ## fastcgi_param HTTPS on;
    }
}

Website :
server {
    listen 80 default_server;
    listen 443 default_server ssl;
    server_name www.mondomaine.fr;

    charset utf-8;
    index index.php;
    client_max_body_size 10M;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html { root /usr/share/nginx/html; }

    location = /favicon.ico {
        access_log off;
        log_not_found off;
    }

    ## début config rutorrent ##

    location ^~ / {
        root /var/www;
        include /etc/nginx/conf.d/php;
        include /etc/nginx/conf.d/cache;
        rewrite ^([_a-z0-9]*).html$  template.php?url=$1;
    }
}
/etc/nginx/nginx.con :
user www-data;
worker_processes auto;

pid /var/run/nginx.pid;
events { worker_connections 1024; }

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

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

    sendfile on;
    keepalive_timeout 20;
    keepalive_disable msie6;
    keepalive_requests 100;
    tcp_nopush on;
    tcp_nodelay off;
    server_tokens off;

    gzip on;
    gzip_buffers 16 8k;
    gzip_comp_level 5;
    gzip_disable "msie6";
    gzip_min_length 20;
    gzip_proxied any;
    gzip_types text/plain text/css application/json  application/x-javascript text/xml application/xml application/xml+rss  text/javascript;
    gzip_vary on;

    include /etc/nginx/sites-enabled/*.conf;
}
Merci d'avance pour votre aide, c'est pas facile d'apprendre sur le tas ^^
de ce que j'ai lu pour l'utf-8 sous nginx, il faut :

# /etc/nginx/nginx.conf

http {
charset utf-8;
}

tu n'as pas cette directive dans nginx.conf

puis un petit

service nginx reload
Hello,

j'avais déjà essayé, mais cela n'a pas résolu le problème.

J'ai regardé sur le dépôt, s'il y avait un paquet à téléchargé (lol..).

Je suis tombé sur ceci : http://nginx.org/en/docs/http/ngx_http_charset_module.html

Aucune idée, si le module est activé ou non.. et comment l'activer... Je suis en train de chercher
charset	utf-8;
Bonjour,

comme l'a dit corentin80, c'est bien au travers de cette directive que Nginx utilise le UTF-8 comme charset.
Nginx le gère par défaut et ce depuis un bon moment. Ainsi, il n'y a aucun module à activer.
À mon avis, le problème vient d'ailleurs (l'encodage des fichiers ?).
J'ai testé, cela provient bien de l'encodage des fichiers. Bizarre, cela marchait parfaitement sous apache... En changeant d'IDE, j'ai remarqué que le problème venait effectivement des fichiers.

Pour l'url rewriting, si j'ai bien compris ça passe aussi par le nginx.conf, et pas de .htaccess ou bien ? Actuellement il me met des pages 404 :-/

(et après à l'attaque pour cakebox 😀)
Ainsi, c'était bien ça ^^. C'est en effet bizarre...

C'est exact. Un fichier .htaccess ne fonctionnera pas, Nginx n'a pas était conçu pour.
Bien, plus qu'à voir si c'est fiable. J'en ai entendu parler mais sans plus.
Mouais, ça marche pas des masses ^^

.htaccess
# Url Rewriting
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([_a-z0-9]*).html$  template.php?url=$1 [L]
website.conf
    location / {
        root /var/www;
        include /etc/nginx/conf.d/php;
        include /etc/nginx/conf.d/cache;                                                                                                                                                                                                    $
        rewrite ^/([_a-z0-9]*).html$ /template.php?url=$1
        break;
    }
Bonjour colle ceci dans ton header ou les fichiers concernés de ton site cela va rectifier les problemes de caracteres
<?php

header('Content-Type: text/html;charset=ISO-8859-1');

?>
Cela va resoudre ton probléme
Merci olivers, mais j'ai corrigé le problème ^^

Maintenant celui qui se pose c'est le regex... Je sais pas s'il est correct (du moins avec apache ça tournait 😀), ou si le problème provient de Nginx 😐

Et après je passerais à cakebox-light -_-
Je m'y connais peu en regex et l'url rewriting... Du moins, je doute qu'il existe des différences dans le cas présent pour la regex. Ainsi, je pencherais plutôt sur un défaut de la config de Nginx mais quoi ?
Déjà il doit se situé dans le fichier de conf, entre location / { ... }

Sur apache celui du .htaccess, ça marche impec'. Cependant lorsque je le teste sur des sites j'ai l'impression qu'il merde

J'essaye de récupérer la variable $url dans index.php.

En gros www.mondomaine.fr/index.php?url=monlien
devient www.mondomaine.fr/monlien

Il faudrait réecrire "index.php?url=" et chopper "monlien"
Pour revenir à Cakebox :

Rutorrent marche parfaitement à l'adresse rutorrent.mondomaine.fr

Cependant cakebox m'affiche une erreur 502. Le sous domaine a été mis en place. (c'était rapide pour celui de rutorrent).

J'ai crée le fichier "/var/www/cakebox/config/sqdz.php" et "/etc/nginx/sites-enabled/cakebox.conf".

cakebox.conf :
server {
    listen 80;
    server_name cakebox.mondomaine.fr; ## sous domaine obligatoire // j'ai modifié mondomaine par le vrai [img]/assets/images/smileys/wink.png[/img]

    root /var/www/cakebox/public;
    index index.php;

    auth_basic "seedbox";
    auth_basic_user_file "/etc/nginx/passwd/rutorrent_passwd";

    charset utf-8;
    include /etc/nginx/conf.d/cache;

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

    location = / {
        try_files @site @site;
    }

    location / {
        try_files $uri $uri/ @site;
    }

    location /sqdz/ {
        alias /home/sqdz/torrents/;
        add_header Content-Disposition "attachment";
        satisfy any;
        allow all;
    }

    ## etc si d'autre utilisateur ##

    location @site {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        fastcgi_param APPLICATION_ENV production;

        ## uncomment when running via https
        ## fastcgi_param HTTPS on;
    }
}
Une idée ?
Bon.. j'ai supprimé cakebox-light, recommencé le tuto de A à Z. Toujours l'erreur 502 :-/

Logs de cakebox :
2014/05/17 14:23:14 [crit] 1040#0: *768 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upcakebox, client: 82.236.180.50, server: cakebox.mondomaine.fr, request: "GET / HTTP/1.1", upcakebox: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "cakebox.mondomaine.fr"
2014/05/17 14:23:14 [crit] 1040#0: *768 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upcakebox, client: 82.236.180.50, server: cakebox.mondomaine.fr, request: "GET /favicon.ico HTTP/1.1", upcakebox: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "cakebox.mondomaine.fr"
2014/05/17 14:23:14 [crit] 1040#0: *768 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upcakebox, client: 82.236.180.50, server: cakebox.mondomaine.fr, request: "GET /favicon.ico HTTP/1.1", upcakebox: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "cakebox.mondomaine.fr"
2014/05/17 15:44:54 [crit] 5763#0: *8 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upcakebox, client: 82.236.180.50, server: cakebox.mondomaine.fr, request: "GET / HTTP/1.1", upcakebox: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "cakebox.mondomaine.fr"
2014/05/17 15:44:57 [crit] 5763#0: *8 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upcakebox, client: 82.236.180.50, server: cakebox.mondomaine.fr, request: "GET / HTTP/1.1", upcakebox: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "cakebox.mondomaine.fr"
2014/05/17 15:44:57 [crit] 5763#0: *8 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upcakebox, client: 82.236.180.50, server: cakebox.mondomaine.fr, request: "GET / HTTP/1.1", upcakebox: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "cakebox.mondomaine.fr"
2014/05/17 15:47:23 [crit] 5766#0: *90 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upcakebox, client: 82.236.180.50, server: cakebox.mondomaine.fr, request: "GET / HTTP/1.1", upcakebox: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "cakebox.mondomaine.fr", referrer: "http://rutorrent.mondomaine.fr/"
2014/05/17 15:55:03 [crit] 5766#0: *545 connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upcakebox, client: 82.236.180.50, server: cakebox.mondomaine.fr, request: "GET / HTTP/1.1", upcakebox: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "cakebox.mondomaine.fr", referrer: "http://rutorrent.mondomaine.fr/"

EDIT : Je devais être un peu dans le gaz pendant l'installation de rtorrent...
J'avais oublié de modifier LISTEN (listen = /var/run/php5-fpm.sock)

EDIT 2 : En modifiant cette variable, cela casse ma config rutorrent et website. (qui devient du coup indisponible.. >_<')

Un petit soucis avec "/etc/php5/fpm/pool.d/www.conf". Lorsque je passe LISTEN = 127.0.0.1:9000 Rutorrent, mon site tourne, cakebox plante. Lorsque j'indique /var/run/php5-fpm.sock Cakebox marche, mais le reste plante
Pour terminer :
LISTEN = 127.0.0.1:9000 -> Rutorrent + website OK // cakebox plante.
LISTEN = /var/run/php5-fpm.sock -> Rutorrent + website plantent // cakebox ok.

J'ai vu que rutorrent utilise du SCGI et cakebox du fastcgi (si je ne m'abuse ?)

Bref, j'ai finis par supprimer cakebox. Je stream via ftp avec XBMC (directement sur la télé), c'est beaucoup plus pratique pour moi ^^.

Cependant si quelqu'un peut m'expliquer le problème, ma curiosité en serait ravi (même 1an plus tard ) J'ai bien compris ce que fait le CGI, mais je reste coincer sur ce problème
Répondre…