Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. # Création d'un Virtual Host sous nginx
  2.  
  3. ## 1. Ajout d'un vhost PHP
  4.  
  5. ```sh
  6. #/etc/nginx/sites-available/
  7.  
  8. server {
  9. listen 80;
  10. root /var/www/source;
  11. index index.html index.htm index.nginx-debian.html index.php;
  12. server_name source;
  13.  
  14. location / {
  15. try_files $uri $uri/ =404;
  16. }
  17.  
  18. location ~ \.php$ {
  19. include snippets/fastcgi-php.conf;
  20. fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
  21. }
  22. }
  23. ```
  24.  
  25. ## 2. Ajout d'un vhost PHP Symfony
  26.  
  27. ```sh
  28. #/etc/nginx/sites-available/
  29.  
  30. server {
  31. server_name overwatch;
  32. root /var/www/overwatch/public;
  33.  
  34. location / {
  35. # try to serve file directly, fallback to index.php
  36. try_files $uri /index.php$is_args$args;
  37. }
  38.  
  39. location ~ ^/index\.php(/|$) {
  40. fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
  41. fastcgi_split_path_info ^(.+\.php)(/.*)$;
  42. include fastcgi_params;
  43.  
  44. fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
  45. fastcgi_param DOCUMENT_ROOT $realpath_root;
  46. internal;
  47. }
  48.  
  49. location ~ \.php$ {
  50. return 404;
  51. }
  52.  
  53. #error_log /var/log/nginx/project_error.log;
  54. #access_log /var/log/nginx/project_access.log;
  55. }
  56. ```
  57.  
  58. ## 3. Activer un vhost
  59.  
  60. ```sh
  61. #sudo ln -s /etc/nginx/sites-available/<vhostFilename> /etc/nginx/sites-enabled/<vhostFilename>
  62. sudo ln -s /etc/nginx/sites-available/source.conf /etc/nginx/sites-enabled/source.conf
  63. ```
  64.  
  65. ## 4. Ajouter un Host
  66.  
  67. ```sh
  68. #/etc/hosts
  69.  
  70. #127.0.0.1 <projectUrl>
  71. 127.0.0.1 source
  72. ```
  73.  
  74. ## 5. Relancer Nginx
  75.  
  76. ```sh
  77. sudo service nginx restart
  78. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement