Nginx + PHP-FPM设置虚拟主机 + 开启PATHINFO模式

/usr/local/nginx/conf/nginx.conf

  1. user nginx nginx;
  2. worker_processes 2;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;
  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '$status $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';
  16. #access_log logs/access.log main;
  17. sendfile on;
  18. #tcp_nopush on;
  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;
  21. gzip on;
  22. client_max_body_size 5m;
  23. #设置404
  24. fastcgi_intercept_errors on;
  25. include vhost/*.conf;
  26. }

/usr/local/nginx/conf/vhost/www.example.com.conf

  1. server {
  2. listen 80;
  3. server_name www.example.com example.com;
  4. charset utf-8;
  5. access_log /data/log/nginx/example.access.log;
  6. root /data/example/www;
  7. if ($host != 'www.example.com') {
  8. rewrite ^/(.*)$ http://www.example.com/$1 permanent;
  9. }
  10. location /favicon.ico {
  11. log_not_found off;
  12. access_log off;
  13. }
  14. location / {
  15. index index.php index.html index.htm;
  16. if (!-e $request_filename) {
  17. rewrite ^/(.*)$ /index.php/$1 last;
  18. }
  19. }
  20. location ~ \.php(/|$) {
  21. fastcgi_split_path_info ^(.+?\.php)(/.*)$;
  22. fastcgi_pass unix:/dev/shm/php-fpm.sock;
  23. fastcgi_index index.php;
  24. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  25. fastcgi_param PATH_INFO $fastcgi_path_info;
  26. include fastcgi_params;
  27. }
  28. location ~ /\.ht {
  29. deny all;
  30. }
  31. }

/usr/local/php/etc/php-fpm.conf

  1. pid = run/php-fpm.pid
  2. user = nginx
  3. group = nginx
  4. ;listen = 127.0.0.1:9000
  5. listen = /dev/shm/php-fpm.sock
  6. listen.owner = nginx
  7. listen.group = nginx
  8. listen.mode = 0660

/usr/local/php/etc/php-fpm.d/www.conf

现在nginx多了一个php-fpm.d/www.conf,把之前在php-fpm.conf里面的一些配置分到了php-fpm.d下面的多个conf里面

  1. user = nginx
  2. group = nginx
  3. ;listen = 127.0.0.1:9000
  4. listen = /dev/shm/php-fpm.sock
  5. listen.owner = nginx
  6. listen.group = nginx
  7. listen.mode = 0660