« Nginx and Ubuntu » : différence entre les versions

De Banane Atomic
Aller à la navigationAller à la recherche
Ligne 42 : Ligne 42 :


= [http://wiki.nginx.org/MediaWiki Mediawiki] =
= [http://wiki.nginx.org/MediaWiki Mediawiki] =
== Pretty URL avec php-fpm ==
<filebox fn='/etc/nginx/site-availables/mediawiki.conf'>
<filebox fn=/etc/nginx/nginx.conf lang=bash>
location / {
    # Do this inside of a location so it can be negated
    location ~ \.php$ {
        try_files      $uri =404;
        fastcgi_pass    unix:/var/run/php-fpm/php-fpm.sock;
        include        /etc/nginx/fastcgi.conf;
    }
}
 
# Handling for the article path
location /wiki {
    fastcgi_pass    unix:/var/run/php-fpm/php-fpm.sock;
    include        /etc/nginx/fastcgi.conf;
    # article path should always be passed to index.php
    fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
</filebox>
<filebox fn=LocalSettings.php lang=php>
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;
</filebox>
 
== URL classique ==
<filebox fn=/etc/nginx/nginx.conf lang=bash>
server {
server {
    server_name mediawiki.domain.net;
     listen      80;
     listen      80;
    server_name myserver;
     root        /var/www/mediawiki;
     root        /srv/http/myserverfolder;
     index      index.php;
     index      index.php;
    # Restrictions based on the .htaccess files
    location ~ /cache|images/deleted|languages|maintenance|maintenance/archives|serialized|tests/ {
        deny all;
    }
    # est-ce vraiment utile ?
    # location ~ /docs|extensions|includes|mw-config|resources|scripts/ {
    #    internal;
    # }
    # ne semble pas nécessaire
    # réécrit les urls: /index.php/Sujet → /index.php?title=Sujet
    # location / {
    #    try_files $uri $uri/ @rewrite;
    # }
    # location @rewrite {
    #    rewrite ^/(.*)$ /index.php?title=$1&$args;
    # }
    # est-ce vraiment utile ?
    # Keep images and CSS around in browser cache for as long as possible, to cut down on server load
    # location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    #    try_files $uri /index.php;
    #    expires max;
    #    log_not_found off;
    # }


     location ~ \.php$ {
     location ~ \.php$ {
         try_files $uri =404;
         include snippets/fastcgi-php.conf;
         fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
         fastcgi_pass unix:/run/php/php-fpm.sock;
        fastcgi_index  index.php;
        include        /etc/nginx/fastcgi.conf;
     }
     }
}
</filebox>
</filebox>
{{info | Le fichier <tt>robots.txt</tt> devra correspondre aux urls de type <tt><nowiki>/index.php?title=MonTitre</nowiki></tt>}}

Version du 9 août 2023 à 18:05

Install

Bash.svg
ai nginx php-fpm

# check nginx and php-fpm are running
sc-status nginx
sc-status php8.2-fpm

UWSGI

Bash.svg
ai uwsgi-plugin-php
# uwsgi dependencies: libjansson4 libnorm1 libpgm-5.2-0 libzmq5 uwsgi-core
# uwsgi-plugin-php dependencies: libphp-embed libphp8.2-embed php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-phpdbg php7.4-readline
# wrongly install php7.4 dependencies while php8.2 is installed

Site configuration

Bash.svg
# enable a web site
sudo ln -s /etc/nginx/sites-available/phpinfo.conf /etc/nginx/sites-enabled/phpinfo.conf
sc-restart nginx

phpinfo

/etc/nginx/sites-available/phpinfo.conf
server {
    listen 80;
    root /var/www/php;
    index info.php;
    server_name phpinfo.net;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/run/php/php-fpm.sock;
    }
}

Mediawiki

/etc/nginx/site-availables/mediawiki.conf
server {
    server_name mediawiki.domain.net;
    listen      80;
    root        /var/www/mediawiki;
    index       index.php;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php-fpm.sock;
    }
}