Advertisement
para_bellum

nginx et php

Jan 25th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. Nginx utilise fastcgi et donc php en fpm.
  2. /etc/nginx/fastcgi_params :
  3.  
  4. fastcgi_param QUERY_STRING $query_string;
  5. fastcgi_param REQUEST_METHOD $request_method;
  6. fastcgi_param CONTENT_TYPE $content_type;
  7. fastcgi_param CONTENT_LENGTH $content_length;
  8.  
  9. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  10. fastcgi_param SCRIPT_NAME $fastcgi_script_name;
  11. fastcgi_param PATH_INFO $fastcgi_path_info;
  12. fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
  13. fastcgi_param REQUEST_URI $request_uri;
  14. fastcgi_param DOCUMENT_URI $document_uri;
  15. fastcgi_param DOCUMENT_ROOT $document_root;
  16. fastcgi_param SERVER_PROTOCOL $server_protocol;
  17. fastcgi_param HTTPS $https if_not_empty;
  18.  
  19. fastcgi_param GATEWAY_INTERFACE CGI/1.1;
  20. fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
  21.  
  22. fastcgi_param REMOTE_ADDR $remote_addr;
  23. fastcgi_param REMOTE_PORT $remote_port;
  24. fastcgi_param SERVER_ADDR $server_addr;
  25. fastcgi_param SERVER_PORT $server_port;
  26. fastcgi_param SERVER_NAME $server_name;
  27.  
  28. # PHP only, required if PHP was built with --enable-force-cgi-redirect
  29. fastcgi_param REDIRECT_STATUS 200;
  30.  
  31. Exemple de configuration :
  32.  
  33. location ~ [^/]\.php(/|$) {
  34. fastcgi_split_path_info ^(.+?\.php)(/.*)$;
  35. root /var/www/facetious-pelican/html/;
  36. if (!-f $document_root$fastcgi_script_name) {
  37. return 404;
  38. }
  39. fastcgi_pass unix:/var/run/php5-fpm.sock;
  40. fastcgi_index index.php;
  41. include /etc/nginx/fastcgi_params;
  42. }
  43.  
  44. Le site se trouve dans /var/www/facetious-pelican/html/.
  45. Le fichier appelé, test/test.php, contient ceci :
  46.  
  47. <pre><?php var_export($_SERVER)?></pre>
  48.  
  49. Et il renvoie ceci :
  50.  
  51. array (
  52. 'USER' => 'www-data',
  53. 'HOME' => '/var/www',
  54. 'FCGI_ROLE' => 'RESPONDER',
  55. 'QUERY_STRING' => '',
  56. 'REQUEST_METHOD' => 'GET',
  57. 'CONTENT_TYPE' => '',
  58. 'CONTENT_LENGTH' => '',
  59. 'SCRIPT_FILENAME' => '/var/www/facetious-pelican/html/test/test.php',
  60. 'SCRIPT_NAME' => '/test/test.php',
  61. 'PATH_INFO' => '',
  62. 'PATH_TRANSLATED' => '/var/www/facetious-pelican/html',
  63. 'REQUEST_URI' => '/test/test.php',
  64. 'DOCUMENT_URI' => '/test/test.php',
  65. 'DOCUMENT_ROOT' => '/var/www/facetious-pelican/html',
  66. 'SERVER_PROTOCOL' => 'HTTP/1.1',
  67. 'GATEWAY_INTERFACE' => 'CGI/1.1',
  68. 'SERVER_SOFTWARE' => 'nginx/1.4.4',
  69. 'REMOTE_ADDR' => '127.0.0.1',
  70. 'REMOTE_PORT' => '54654',
  71. 'SERVER_ADDR' => '127.0.0.1',
  72. 'SERVER_PORT' => '80',
  73. 'SERVER_NAME' => 'facetious-pelican',
  74. 'REDIRECT_STATUS' => '200',
  75. 'HTTP_HOST' => 'facetious-pelican',
  76. 'HTTP_USER_AGENT' => 'Mozilla/5.0 (X11; Linux i686; rv:20.0) Gecko/20100101 Firefox/20.0 Iceweasel/20.0',
  77. 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  78. 'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.5',
  79. 'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
  80. 'HTTP_CONNECTION' => 'keep-alive',
  81. 'HTTP_CACHE_CONTROL' => 'max-age=0',
  82. 'PHP_SELF' => '/test/test.php',
  83. 'REQUEST_TIME_FLOAT' => 1390690367.819366,
  84. 'REQUEST_TIME' => 1390690367,
  85. )
  86.  
  87.  
  88. Sources et références :
  89. http://wiki.nginx.org/PHPFcgiExample
  90.  
  91. Infos système :
  92. para@para-clevo:/etc/nginx$ php5-fpm --version
  93. PHP 5.5.8-2 (fpm-fcgi) (built: Jan 12 2014 10:36:01)
  94. Copyright (c) 1997-2013 The PHP Group
  95. Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
  96. with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
  97.  
  98. para@para-clevo:/etc/nginx$ nginx -v
  99. nginx version: nginx/1.4.4
  100.  
  101.  
  102. Il se peut que nginx balance l'erreur suivante : (/var/log/nginx/error.log)
  103. 2014/11/11 22:41:51 [crit] 22493#0: *7159 connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream, client: 81.164.20.137, server: facetious-pelican.fuuu.be, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "facetious-pelican.fuuu.be"
  104.  
  105. => C'est une question de permission sur le socket de php5-fpm.
  106.  
  107. 1/ checker le nom d'utilisateur utilisé par nginx : (/etc/nginx/nginx.conf)
  108. ...
  109. user nginx;
  110. ...
  111.  
  112. 2/ modifier /etc/php5/fpm/pool.d/www.conf :
  113. user = nginx
  114. group = nginx
  115.  
  116. listen.owner = nginx
  117. listen.group = nginx
  118. listen.mode = 0660
  119.  
  120. 3/ sudo service php5-fpm stop
  121. sudo service php5-fpm start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement