Str*_*rae 4 php nginx user-management fastcgi
我对 nginx 很陌生,而且 - 更多用于学习目的 - 我试图配置 Nginx,以便为每个子域使用不同的用户运行 php。
例如,我想将用户john用于所有脚本foo.example.com,用户jack用于bar.example.com.
我已经在我的系统(ubuntu 服务器)上创建了用户,但我不知道如何指示 nginx 使用这些用户 - 我正在寻找一种可以轻松处理许多用户的解决方案,比如 ~2000。
查看文档,我不明白是否必须php5-cgi为每个用户(使用不同的端口)生成一个进程,然后将它们抓取到我的sites-available站点中(正如我所说的我是新手,但这在我看来就像服务器自杀),并且 nginx 配置中仅有的 2 页讨论了这个……是用中文写的(page1 , page2),很难用 google translate 翻译(但是,查看代码,使用的方式完全不同server-suicide)
有什么建议吗?
更新
galador 的回答可以完成这项工作,但我正在尝试构建一个不需要为每个新站点重新启动 nginx/fpm 的 dinamycal 环境(带有通配符子域),这可能吗?
小智 6
编辑:我刚刚注意到您的“需要扩展到 ~2000 个用户”的要求......这可能不是您的最佳选择,但可能可以通过一些脚本轻松实现自动化。
你可以使用php-fpm来做这样的事情(fpm 是PHP 5.3.3以来PHP 的一部分。我在我的 VPS 上托管了几个站点,并使用类似的东西。
我的主要 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
Run Code Online (Sandbox Code Playgroud)
然后,在 fpm.d 文件夹中,我有每个站点的配置文件,如下所示:
[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
Run Code Online (Sandbox Code Playgroud)
然后,对于每个站点,您在他们自己的文件中更改用户和端口,在 nginx 配置中,您将拥有如下内容:
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;
}
Run Code Online (Sandbox Code Playgroud)
更改 fastcgi_pass 指令中的端口。
| 归档时间: |
|
| 查看次数: |
7233 次 |
| 最近记录: |