« Nginx and Ubuntu » : différence entre les versions
Apparence
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 40 : | Ligne 40 : | ||
} | } | ||
</filebox> | </filebox> | ||
= [http://wiki.nginx.org/MediaWiki Mediawiki] = | |||
== Pretty URL avec uwsgi == | |||
<filebox fn=/etc/nginx/nginx.conf lang=bash> | |||
# only in production | |||
error_page 403 404 = /index.php; | |||
location ~ \.php5?$ { | |||
include uwsgi_params; | |||
uwsgi_modifier1 14; | |||
uwsgi_pass unix:/run/uwsgi/mediawiki.sock; | |||
} | |||
location ^~ /wiki/ { | |||
rewrite ^/wiki/(.*)$ /index.php?title=$1; | |||
} | |||
# Restrictions based on the .htaccess files | |||
location ^~ /cache/ { deny all; } | |||
# location ^~ /images/ {} | |||
location ^~ /images/deleted/ { deny all; } | |||
location ^~ /images/temp/ { deny all; } | |||
location ^~ /includes/ { deny all; } | |||
location ^~ /languages/ { deny all; } | |||
location ^~ /maintenance/ { deny all; } | |||
location ^~ /maintenance/archives/ { deny all; } | |||
location ^~ /serialized/ { deny all; } | |||
location ^~ /tests/ { deny all; } | |||
# location ^~ /tests/qunit/ { allow all; } | |||
location ^~ /extensions/MobileFrontend/dev-scripts/ { deny all; } | |||
# location ^~ /extensions/MobileFrontend/tests/ {} | |||
# Restrictions d'accès supplémentaires | |||
location ^~ /mw-config/ { deny all; } | |||
location ^~ /extensions/ { deny all; } | |||
location ^~ /resources/ { deny all; } | |||
location ^~ /resources/assets/ { allow all; } | |||
location ^~ /docs/ { internal; } | |||
location ^~ /vendor/ { internal; } | |||
# Hide any .htaccess files | |||
location ~ /.ht { deny all; } | |||
location ~* \.(js|css|png|jpg|jpeg|svg|gif|ico)$ { | |||
try_files $uri /index.php; | |||
expires max; | |||
} | |||
</filebox> | |||
<filebox fn=LocalSettings.php lang=php> | |||
$wgArticlePath = "/wiki/$1"; | |||
</filebox> | |||
== Pretty URL avec php-fpm == | |||
<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 { | |||
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; | |||
} | |||
</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 à 17:59
Install
ai nginx php-fpm
# check nginx and php-fpm are running
sc-status nginx
sc-status php8.2-fpm
|
UWSGI
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
# 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/php8.2-fpm.sock;
}
}
|
Mediawiki
Pretty URL avec uwsgi
/etc/nginx/nginx.conf |
# only in production
error_page 403 404 = /index.php;
location ~ \.php5?$ {
include uwsgi_params;
uwsgi_modifier1 14;
uwsgi_pass unix:/run/uwsgi/mediawiki.sock;
}
location ^~ /wiki/ {
rewrite ^/wiki/(.*)$ /index.php?title=$1;
}
# Restrictions based on the .htaccess files
location ^~ /cache/ { deny all; }
# location ^~ /images/ {}
location ^~ /images/deleted/ { deny all; }
location ^~ /images/temp/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /languages/ { deny all; }
location ^~ /maintenance/ { deny all; }
location ^~ /maintenance/archives/ { deny all; }
location ^~ /serialized/ { deny all; }
location ^~ /tests/ { deny all; }
# location ^~ /tests/qunit/ { allow all; }
location ^~ /extensions/MobileFrontend/dev-scripts/ { deny all; }
# location ^~ /extensions/MobileFrontend/tests/ {}
# Restrictions d'accès supplémentaires
location ^~ /mw-config/ { deny all; }
location ^~ /extensions/ { deny all; }
location ^~ /resources/ { deny all; }
location ^~ /resources/assets/ { allow all; }
location ^~ /docs/ { internal; }
location ^~ /vendor/ { internal; }
# Hide any .htaccess files
location ~ /.ht { deny all; }
location ~* \.(js|css|png|jpg|jpeg|svg|gif|ico)$ {
try_files $uri /index.php;
expires max;
}
|
LocalSettings.php |
$wgArticlePath = "/wiki/$1";
|
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 |