
Installer un serveur web nginx sous ubuntu 12.04
Comment installer un serveur web performant sous ubuntu 12.04
Présentation du serveur web performant: LNMP
LNMP pour Linux Ngnix MySql Php
Le choix du moteur du serveur web est nginx avec les modules php-fpm et php-xcache, et comme serveur de base de donnée le célèbre MySql-server.
Pur plus d’info sur nginx: http://wiki.nginx.org/NginxFr

Ici le choix de l’os: Ubuntu serveur 12.04
php-fpm pour Php FastCGI sera le module qui traitera toutes les instructions PHP.
Pour ne pas retraiter des instructions PHP inutilement, le module php-xcache s’occupera donc du cache PHP.
Prérequis
Avoir les droits root
passage en root
1 | sudo -s |
Mise à jour des paquets
1 | apt-get update |
Installation de nginx
1 | apt-get install nginx |
on lance nginx
1 | service nginx start |
test dans un navigateur de nginx

Installation de MySql
1 | apt-get install mysql-server mysql-client |
Lors de l’installation, un mot de passe root sera demander.

Puis Sécuriser MySql
Installation de Php
1 | apt-get install php5-fpm php5-mysql php5-xcache |
Astuce: pour connaitre tous les module Php
1 | apt-cache search php5 |
Configuration de nginx
Les fichiers de configuration des sites disponible se trouve, tout comme pour apache2, dans/etc/nginx/sites-available
Et un lien symbolique de chaque configuration des sites disponibles dans /etc/nginx/site-enabled
Par défaut voici la conf de nginx
1 | nano /etc/nginx/sites-enabled/default |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | server { #listen 80; ## listen for ipv4; this line is default and implied #listen [::]:80 default ipv6only=on; ## listen for ipv6 root /usr/share/nginx/www; index index.html index.htm; # Make site accessible from http://localhost/ server_name localhost; location / { # First attempt to serve request as file, then # as directory, then fall back to index.html try_files $uri $uri/ /index.html; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } |
Création d’un fichier de configuration pour un site
1 | touch /etc/nginx/sites-available/site-web01 |
Création du lien symbolique
1 | ln -s /etc/nginx/sites-available/site-web01 /etc/nginx/sites-enabled/ |
Création du répertoire pour le site web, exemple:
1 | mkdir /home/fred/web/ |
1 | mkdir /home/fred/web/site-web01 |
Droits pour www-data sur le répertoire
1 | chown -R www-data:www-data /home/fred/web/ |
Création d’une page de test
1 | nano /home/fred/web/site-web01/index.html |
le code html
1 | <html><body>Page de TEST</body></html> |
Suppression du fichier de configuration default
1 | rm /etc/nginx/sites-enabled/default |
Edition du fichier de configuration
1 | nano /etc/nginx/sites-enabled/site-web01 |
Voici un exemple de configuration simple
1 2 3 4 5 6 7 8 9 10 | server { listen 80; root /home/fred/web/site-web01; index index.html index.htm index.php; # Make site accessible from http://localhost/ server_name www.domaine.tld; location / { try_files $uri $uri/ /index.html; }} |
explication:
listen 80: le serveur web écoute sur le port 80
root /home/fred/web/site-web01: chemin du répertoire du site web
index index.html index.htm index.php: prise en charge des formats .html, .htm et .php
server_name www.domaine.tld: pour que le site soit accessible depuis l’extérieur il faut lui renseigner un vrai nom de domaine.
location / {try_files $uri $uri/ /index.html;}: lors de la requête dans le navigateur s’il n’est pas préciser la page, dans ce cas index.html sera appelé.
Test dans le navigateur:

Prise en charge du PHP
Edition du fichier de configuration du site
1 | nano /etc/ngnix/sites-enabled/site-web01 |
Ajout de la prise en charge PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | server { listen 80; root /home/fred/web/site-web01; index index.html index.htm index.php; # Make site accessible from http://localhost/ server_name localhost; location / { try_files $uri $uri/ /index.html; } #prise en charge PHP location ~ .php$ { fastcgi_pass 127.0.0.1:9000; include /etc/nginx/fastcgi_params; fastcgi_index index.php; }} |
Relance de nginx
1 | service nginx reload |
Edition du fichier index.php
1 | nano index.php |
1 2 3 | <?phpinfo();?> |
Test dans le navigateur

mais le module php-xcache n’est pas encore pris en compte
Prise en charge du module php-xcache
pour ce faire il suffit de relancer php5-fpm
1 | service php5-fpm restart |
Vérification dans le navigateur avec index.php

Conclusion
Avec un minimum d’effort, nous voici avec un serveur web performant léger et robuste ![]()
A savoir, les principaux site pr0n tournent sous nginx ![]()
Bonus: un fichier de configuration Nginx pour WordPress
A savoir:
- ici nginx écoute sur le port 8080
- Mise en cache des fichiers statiques: js|css|png|jpg|jpeg|gif|ico
- redirection en HTTPS pour wp-admin
- blocage par .htaccess à l’accès de wp-admin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | server {listen 8080;server_name memo-linux.com;root /home/fred/www/blog/;access_log /var/log/nginx/access.log;error_log /var/log/nginx/error.log error;index index.php index.phtml index.html # Security include global/security.conf; location / { # This is cool because no php is touched for static content. # include the "?$args" part so non-default permalinks doesn't break#when using query string try_files $uri $uri/ /index.php?$args; } # PHP-FPM include global/php-fpm.conf;location ~ /.ht { deny all;} # STATICS FILES location ~* .(js|css|png|jpg|jpeg|gif|ico)$ { expires max; log_not_found off; }}server{listen 443 ssl; server_name .memo-linux.com; ssl_certificate /etc/nginx/ssl/server.crt; ssl_certificate_key /etc/nginx/ssl/server.key; root /var/www; index index.php; # Process only the requests to wp-login and wp-admin location ~ /(wp-) { auth_basic "Acces DENIED!"; auth_basic_user_file /home/fred/www/rep01/.htpasswd;location ~ .php$ {try_files $uri =404; include fastcgi_params; fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_intercept_errors on; fastcgi_ignore_client_abort off; fastcgi_connect_timeout 60; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffers 4 256k; fastcgi_buffer_size 128k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; } } # Redirect everything else to port 80location / { return 301 http://$host$request_uri; }} |
Création du fichier /etc/nginx/global/php-fpm.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | location ~ .php$ { # The following line prevents malicious php code to be executed through some uploaded file (without php extension, like image) # This fix shoudn't work though, if nginx and php are not on the same server, other options exist (like unauthorizing php execution within upload folder) # More on this serious security concern in the "Pass Non-PHP Requests to PHP" section, there http://wiki.nginx.org/Pitfalls##ATTENTION ici c'est pour la redirection HTTPS!######location ~ /wp-(admin|login) { return 301 https://$host$request_uri; }################################ try_files $uri =404; # PHP # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_intercept_errors on; fastcgi_ignore_client_abort off; fastcgi_connect_timeout 60; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffers 4 256k; fastcgi_buffer_size 128k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k;}
|

Stumbled upon this while browsing forums and the reputation really matches the actual experience. Games load smoothly, promotions rotate regularly, and I never feel pressured to deposit more than planned. A refreshing platform. tezz888
Spinning my way through the weekend and loving every moment. The interface is clean and I can find my favorite slots in just a few taps. Withdrawals are handled faster than I expected and support is always friendly. woospins
Loving the smooth app experience and quick withdrawals. Everything runs so smoothly on my phone. Highly recommend checking out gd333app for daily entertainment. gd333app