如何configurationnginx + php(fcgi)与不同的用户运行每个子域?

我很新的nginx和 – 更多的学习目的 – 即时通讯尝试configurationNginx的运行与不同的用户为每个子域的PHP

例如,我想使用用户johnfoo.example.com上的所有脚本和在bar.example.com上的用户jack

我已经创build了我的系统上的用户(Ubuntu的服务器),但我不知道如何指示nginx使用用户 – 即时寻找一个解决scheme,可以处理easly许多用户,可以说〜2000年。

看文档,我不明白,如果我必须为每个用户(不同的端口)产生一个php5-cgi进程,然后把它们抓到我的sites-available网站(如我说我是一个新手,但这看起来像我一个服务器自杀),而在nginxconfiguration中只有2个页面是用中文( page1 , page2 )来写的,用google翻译很难翻译(但是,看代码,使用完全不同于server-suicide方式)

任何build议?

更新

galador的答案做的工作,但即时通讯设法build立一个dinamycal环境(与通配符子域名)不需要重新启动nginx / fpm每个新的网站,这可能吗?

编辑 :我只是注意到你的“需要扩大到2000用户”的要求…这可能不是你最好的select,但可能很容易通过一些脚本自动化。

你可以使用php-fpm来做这样的事情(fpm是自PHP 5.3.3以来的一部分,我在VPS上托pipe了几个站点,并使用类似的东西。

我的主要的PHP-fpm.conf如下所示:

 ;;;;;;;;;;;;;;;;;;;;; ; FPM Configuration ; ;;;;;;;;;;;;;;;;;;;;; include=/usr/local/etc/fpm.d/*.conf ;;;;;;;;;;;;;;;;;; ; Global Options ; ;;;;;;;;;;;;;;;;;; [global] ; Pid file ; Default Value: none pid = /var/run/php-fpm.pid ; Error log file ; Default Value: /var/log/php-fpm.log error_log = /var/log/php-fpm.log ; Log level ; Possible Values: alert, error, warning, notice, debug ; Default Value: notice ;log_level = notice ; If this number of child processes exit with SIGSEGV or SIGBUS within the time ; interval set by emergency_restart_interval then FPM will restart. A value ; of '0' means 'Off'. ; Default Value: 0 ;emergency_restart_threshold = 0 ; Interval of time used by emergency_restart_interval to determine when ; a graceful restart will be initiated. This can be useful to work around ; accidental corruptions in an accelerator's shared memory. ; Available Units: s(econds), m(inutes), h(ours), or d(ays) ; Default Unit: seconds ; Default Value: 0 ;emergency_restart_interval = 0 ; Time limit for child processes to wait for a reaction on signals from master. ; Available units: s(econds), m(inutes), h(ours), or d(ays) ; Default Unit: seconds ; Default Value: 0 ;process_control_timeout = 0 ; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging. ; Default Value: yes ;daemonize = yes 

然后,在fpm.d文件夹中,我有像这样的每个站点的configuration文件:

 [myuser] listen = 127.0.0.1:9000 listen.allowed_clients = 127.0.0.1 user = myuser group = myuser pm = dynamic pm.max_children = 15 pm.start_servers = 3 pm.min_spare_servers = 1 pm.max_spare_servers = 5 pm.max_requests = 2000 request_slowlog_timeout = 5 slowlog = /home/myuser/tmp/logs/myuser.slow.log php_admin_value[error_log] = /home/myuser/tmp/logs/myuser.error.log php_admin_flag[log_errors] = on 

然后,对于每个站点,您在自己的文件中更改用户和端口,在nginxconfiguration中,您将拥有如下所示的内容:

 location ~ .*.php$ { include /usr/local/etc/nginx/fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } 

更改fastcgi_pass指令中的端口。