logo Debian Debian Debian-France Debian-Facile Debian-fr.org Forum-Debian.fr Debian ? Communautés logo inclusivité

Debian-facile

Bienvenue sur Debian-Facile, site d'aide pour les nouveaux utilisateurs de Debian.

Vous n'êtes pas identifié(e).

#1 06-01-2016 14:19:43

momos73
Membre
Distrib. : Debian 8.7
Noyau : Linux 3.16.0-4-amd64
Inscription : 11-01-2015

Configuration des redirections Nginx

Bonjour à tous et bonne année 2016 à toute l'équipe de debian-facile !

Je possède un serveur web sous debian 7 avec apache php mysql.
J'ai récemment installer Nginx en complément afin d'améliorer la vitesse d'affichage des fichiers statiques.
J'ai réussi à paramétrer correctement mon site "monsite.com" en ajoutant une config dans "/etc/nginx/sites-enabled/default" :


server {

        root /var/www/monsite.com/;
        index index.php;

        # Make site accessible from http://localhost/
        server_name www.monsite.com;

        # Header cache control
        add_header  Cache-Control public;

        # Redirection des fichiers statiques
        location ~* \.(jpg|jpeg|gif|css|png|js|ico|swf|mp3|mp4|svg|eot|ttf|woff|txt|xml|json|pdf|zip|doc|ppt|xls)$ {
                root   /var/www/monsite.com/;
                expires        max;
                access_log     off;
                error_log          off;
                log_not_found  off;
        }

        # Redirection par défaut
        location / {

                proxy_pass                      http://127.0.0.1:8080;
                proxy_redirect          off;
                proxy_set_header        Host            $host;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                client_max_body_size    10m;
                client_body_buffer_size 128k;
                proxy_connect_timeout   90;
                proxy_send_timeout      90;
                proxy_read_timeout      90;
                proxy_buffers           32 4k;

                # Désactivation des logs
                access_log off;
                error_log off;
        }
}
 



Je voudrais désormais paramétrer mon "phpmyadmin", "postfixadmin" et mon "roundcube" afin que les fichiers statiques soient corectement redirigés, j'ai donc essayer de faire ceci :


server {

    index index.php

    # Make site accessible from http://localhost/
    server_name X.X.X.X;

    # Header cache control
    add_header  Cache-Control public;

    # Redirection des fichiers statiques
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|swf|mp3|mp4|svg|eot|ttf|woff|txt|xml|json|pdf|zip|doc|ppt|xls)$ {

        if ($request_uri ~* /phpmyadmin) {
          root /usr/share/;
        }
        if ($request_uri ~* /roundcube) {
          root /usr/share/;
        }
        if ($request_uri ~* /postfixadmin) {
          root /usr/share/;
        }

        expires          max;
        access_log       off;
        error_log        off;
        log_not_found    off;
    }

    # Redirection par défaut
    location / {

        proxy_pass               http://127.0.0.1:8080;
        proxy_redirect          off;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout   90;
        proxy_send_timeout      90;
        proxy_read_timeout      90;
        proxy_buffers           32 4k;

        # Désactivation des logs
        access_log off;
        error_log off;
    }
}
 



Mais cela n'a aucun effet je n'est pas d'erreur de syntaxe quand je redémarre nginx mais mes fichiers statiques sont mal redirigés.


Merci pour votre aide

Hors ligne

#2 10-01-2016 18:29:13

aurel-son
Membre
Lieu : Vietnam/Paris
Distrib. : Stable/Testing
Noyau : 4.8.x
(G)UI : Mate
Inscription : 23-03-2015
Site Web

Re : Configuration des redirections Nginx

Salut,

Tu devrais plutot faire du genre :


server {

    index index.php

    # Make site accessible from http://localhost/
    server_name X.X.X.X;

    # Header cache control
    add_header  Cache-Control public;

    # Redirection des fichiers statiques
    location ~* \.(jpg|jpeg|gif|css|png|js|ico|swf|mp3|mp4|svg|eot|ttf|woff|txt|xml|json|pdf|zip|doc|ppt|xls)$ {


        if ($request_uri ~* /roundcube) {
          root /usr/share/;
        }
        if ($request_uri ~* /postfixadmin) {
          root /usr/share/;
        }

        expires          max;
        access_log       off;
        error_log        off;
        log_not_found    off;

    location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
        }

        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
        }
    }

    location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
    # Redirection par défaut
    location / {

        proxy_pass               http://127.0.0.1:8080;
        proxy_redirect          off;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size    10m;
        client_body_buffer_size 128k;
        proxy_connect_timeout   90;
        proxy_send_timeout      90;
        proxy_read_timeout      90;
        proxy_buffers           32 4k;


    }
 

Dernière modification par aurel-son (10-01-2016 18:31:29)


Desktop : Debian Jessie Mate/Kali
Serveur/NAS/firewall : Debian stable,Centos,BSD

Hors ligne

Pied de page des forums