首页 Nginx 如何配置nginx php(fcgi)以使用不同的用户运行每个子域?

如何配置nginx php(fcgi)以使用不同的用户运行每个子域?

我对nginx很新,而且 – 更多用于学习目的 – 我试图配置Nginx以便为每个子域运行不同用户的php.例如,我想在foo.example.com上使用用户john,在bar.example.com上使用用户jack.我已经在我的系统(ubuntu服务器)上创建了用户,但我不知道如何指示nginx使用用户 – 我

我对nginx很新,而且 – 更多用于学习目的 – 我试图配置Nginx以便为每个子域运行不同用户的php.

例如,我想在foo.example.com上使用用户john,在bar.example.com上使用用户jack.

我已经在我的系统(ubuntu服务器)上创建了用户,但我不知道如何指示nginx使用用户 – 我正在寻找一个可以轻松处理许多用户的解决方案,比如说2000.

看文档,我不明白我是否必须为每个用户(使用不同的端口)生成一个php5-cgi进程,然后将它们抓到我的网站 – 可用网站(正如我所说的一个新手,但这看起来像我一个服务器自杀),nginx配置中只有2页谈论这个…是用中文写的(page1,page2),用谷歌翻译难以翻译(但是,查看代码,使用完全不同于服务器自杀方式)

有什么建议吗?

更新

galador的答案可以完成这项工作,但我试图构建一个dinamycal环境(带有通配符子域),不需要为每个新站点重新启动nginx / fpm,这可能吗?

最佳答案
编辑:我刚刚注意到你的“需要扩展到~2000用户”的要求……这可能不是你最好的选择,但可能很容易通过一些脚本自动化.

您可以使用php-fpm来执行此类操作(自PHP 5.3.3起,fpm是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),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文件夹中,我有每个站点的配置文件,如下所示:

[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

然后,对于每个站点,您在自己的文件中更改用户和端口,并在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;
}

更改fastcgi_pass指令中的端口.

本文来自网络,不代表云浮站长网立场。转载请注明出处: https://www.0766zz.com/html/yunying/nginx/20200901/9402.html
上一篇
下一篇

作者: dawei

【声明】:云浮站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

返回顶部