在nginx中运行PHP的虚拟目录

时间:2013-02-08 16:02:48

标签: php tomcat nginx virtual-directory

是否有正确的方法来指定应该在nginx中发送虚拟目录的后端内容?目前,我有一个运行nginx的站点,其中tomcat和PHP-FPM默认情况下将请求发送到tomcat,我想添加一个名为dbadmin的虚拟目录(此目录的内容存储在磁盘上完全不同的位置),其中包含phpmyadmin请求被发送到PHP-FPM套接字。

我当前的配置(conf.d / default.conf):

server {
  listen       80 default_server;
  server_name  mydomain.com;
  root         /opt/apache-tomcat/webapps;

  # cache statis files for 1 month
  location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
    access_log        off;
    log_not_found     off;
    expires           30d;
  }

  # deny access to hidden files (.whatever)
  location ~ /\. {
    access_log off;
    log_not_found off;
    deny all;
  }

  location ~ /dbadmin/(.*)$
  {
    index index.php;
    alias /opt/www/phpmyadmin/$1;
  }

  location ~* \.php$ {
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    /opt/www/phpmyadmin$fastcgi_script_name;
    fastcgi_index  index.php;

    if (-f $request_filename) {
      fastcgi_pass phpfpm;
    }
  }

  location / {
    # increase timeout to 2 min
    proxy_read_timeout        120;

    # needed to forward user IP address
    proxy_set_header          X-Real-IP $remote_addr;

    # https support
    proxy_set_header          X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header          Host $http_host;

    proxy_redirect            off;
    proxy_pass                http://127.0.0.1:8080;
  }
}

phpfpm在main nginx.conf中定义:

upstream phpfpm {
  ip_hash;
  server unix:/var/run/php-fpm/php-fpm.sock;
}

1 个答案:

答案 0 :(得分:1)

阅读你的代码,我认为解决方案可以在你将.php文件发送到php-fpm的方式中找到,通常你应该尝试这样的东西....

location ~* \.php$ {    
fastcgi_pass  127.0.0.1:9000;          # if using tcp/ip
fastcgi_pass unix:/tmp/php5-fpm.sock;  # if using sockets
}
相关问题