0

I'm setting up a vhost for my magento site. So basically I have 2 store namely store1 and store2. Since this 2 store is using the same code and DB I setup the vhost in NGINX almost identical. The only difference are their server_name now when I try to restart my nginx I get the emerg duplicate upstream "fastcgi_backend" error. Not sure what happen. Below is my code

upstream fastcgi_backend {
    server unix:/var/run/php/php7.4-fpm.sock;
}

server {
    listen 80;
    listen 443 ssl http2;
    server_name site1.com.test;
    set $MAGE_MODE developer;
    set $MAGE_ROOT /home/vagrant/code;
    include /home/vagrant/code/nginx.conf.sample;

    index index.html index.htm index.php;
    sendfile off;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
    }

    location ~ /\.ht {
        deny all;
    }

    ssl_certificate     /etc/nginx/ssl/site1.com.test.crt;
    ssl_certificate_key /etc/nginx/ssl/site1.com.test.key;
}

And here is my conf for the second site

upstream fastcgi_backend {
    server unix:/var/run/php/php7.4-fpm.sock;
}

server {
    listen 80;
    listen 443 ssl http2;
    server_name site2.com.test;
    set $MAGE_MODE developer;
    set $MAGE_ROOT /home/vagrant/code;
    include /home/vagrant/code/nginx.conf.sample;

    index index.html index.htm index.php;
    sendfile off;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
    }

    location ~ /\.ht {
        deny all;
    }

    ssl_certificate     /etc/nginx/ssl/site2.com.test.crt;
    ssl_certificate_key /etc/nginx/ssl/site2.com.test.key;
}

So it's almost identical except for the servername. But I have no idea why I'm getting this error emerg duplicate upstream "fastcgi_backend"

Would really appreciate any help here.

Note: I only tried just 1 config in the site-enabled and the config was working. Only when I try to load/enable a second site that I experience that error

1
  • The two upstream statements with the same name are causing the conflict, but you are not using them anyway. Delete the two upstream blocks and restart. Commented Jun 24, 2020 at 6:28

1 Answer 1

3

Consider fastcgi_backend as just any variable name. Since you have two projects nginx reads both the conf files and finds that fastcgi_backend is used multiple times. If you are running both the projects with same fpm socket then you can remove either one, but if you have multiple php versions set up and hence are using different fpm socket, change fastcgi_backend to any name in one of the projects. Make sure that you use the changed name in your nginx.conf.sample file too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.