大网数据广告活动
服务器运维问答

Multiple magento sites running under different users in nginx

· 52CE 我爱测

I have written a script that copies magento files and database from our production server and tries to configure it on a subdomain on our testing server. Each testing site has: - unique subdomain - running under unique user speci…

问题原文

原帖链接 · Guerrilla · CC BY-SA 3.0

I have written a script that copies magento files and database from our production server and tries to configure it on a subdomain on our testing server.

Each testing site has: - unique subdomain - running under unique user specified in php-fpm pool

Here is the php-fpm pool config:

[test1]
user = test1
group = test1
listen = /run/php/php7.0-test1-fpm.sock
listen.owner = www-data
listen.group = www-data

So I would set up subsequent sites under different users like so:

[test2]
user = test2
group = test2
listen = /run/php/php7.0-test2-fpm.sock
listen.owner = www-data
listen.group = www-data

The problem comes when I try to duplicate the magento nginx server block (abbreviated version pasted below):

 upstream fastcgi_backend {
     server  unix:/run/php-fpm/php-test1-fpm.sock;
 }

 server {

     listen 80;
     server_name test1.magento-dev.com;
     set $MAGE_ROOT /usr/share/nginx/html/test1;
     include /usr/share/nginx/html/test1/nginx.conf.sample;
 }

If I duplicate the config like so:

 upstream fastcgi_backend {
     server  unix:/run/php-fpm/php-test2-fpm.sock;
 }

 server {

     listen 80;
     server_name test2.magento-dev.com;
     set $MAGE_ROOT /usr/share/nginx/html/test2;
     include /usr/share/nginx/html/test2/nginx.conf.sample;
 }

I get error because the fastcgi_backend upsteam is already defined. I read the nginx documentation for upstream and it says it is a pool of servers but I don't really understand what is going on here to specify upstream like this to handoff php requests.

What am I doing wrong? How should I setup multiple magento sites on subdomains running under different users?

How I fixed it:

I renamed the upstream but I didn't realise that the upstream name is used in proxy_pass. You have to edit the proxy_pass in nginx.conf.sample in magento root.

已采纳解答

原帖链接 · Tim · CC BY-SA 4.0

Here's how I set up multiple pools using Nginx and PHP 5.6. I don't use paths, I use sockets. I've slightly edited my files to make them more generic, so if anything doesn't match assume it's a typo.

/etc/php-fpm-5.6.d/pool1

[pool1]
listen = 127.0.0.1:9000

/etc/php-fpm-5.6.d/pool2

[pool2]
listen = 127.0.0.1:9001

/etc/nginx/upstreams.conf

upstream php56-pool1 {
    server 127.0.0.1:9000;
}

upstream php56-pool2 {
    server 127.0.0.1:9001;
}

Here are relevant parts of my Nginx location blocks.

/etc/nginx/site1.conf

location ~ \.php$ {
    fastcgi_pass   php56-pool1;
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_index index.php;
}

/etc/nginx/site2.conf

location ~ php$ {
    fastcgi_pass php56-pool2;
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-12-20)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。