Nginx and Ubuntu

De Banane Atomic
Aller à la navigationAller à la recherche

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

Pretty URL avec php-fpm

/etc/nginx/nginx.conf
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;
}
LocalSettings.php
$wgArticlePath = "/wiki/$1";
$wgUsePathInfo = true;

URL classique

/etc/nginx/nginx.conf
server {
    listen      80;
    server_name myserver;
    root        /srv/http/myserverfolder;
    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$ {
        try_files $uri =404;
        fastcgi_pass    unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index   index.php;
        include         /etc/nginx/fastcgi.conf;
    }
Le fichier robots.txt devra correspondre aux urls de type /index.php?title=MonTitre