Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento 2 in subfolder Nginx

Tags:

nginx

magento

Using Nginx 1.4.6 on Ubuntu, i'm trying to configure Magento 2 to run in a subfolder.

I already have some others projets in /var/www, that are set up like so:

server {
    server_name website.com;

    root /var/www/;

    location /p1/ {
        # config
    }

    location /p2/ {
        # config
    }
}

But now, my Magento installation is located at /mnt/storage/demo/demo-magento2 and I can't find a way to include it in this server block.

I tried to use their sample configuration for Nginx (https://github.com/magento/magento2/wiki/Nginx-Configuration-Settings-and-Environment-Variables). So, I added this location block to my server block configuration:

location /demos/demo-magento2/ {
  set $MAGE_ROOT /mnt/storage/demo-magento2/;
  set $MAGE_MODE developers;
  include /mnt/storage/demo-magento2/nginx.conf.sample;
}

And Nginx keeps returning me this error:

2015/10/19 18:15:04 [emerg] 6250#0: location "/setup" is outside location "/demos/demo-magento2/" in /mnt/storage/demo-magento2/nginx.conf.sample:27

I am quite new to Nginx, so can someone explains me how to figure it out?

like image 237
ClementParis016 Avatar asked Oct 19 '22 00:10

ClementParis016


2 Answers

Nginx configuration is picky about where directives are located; because Magento's nginx.conf.sample contains 'location' directives, it must be included from inside a "server" directive. Take a look at the commented out portion at the top of the sample config; it shows roughly what the main configuration file should like.

You should have a root configuration file which looks like this:

upstream fastcgi_backend {
        server unix:/var/run/php5-fpm.sock;
}

server {
    listen 80;
    server_name server.dev;
    set $MAGE_ROOT /path/to/magento2;
    set $MAGE_MODE developer;
    include /path/to/magento2/nginx.conf.sample;
 }

And if you're using the typical Ubuntu-nginx setup, you'll want that file under the /etc/nginx/sites-available directory, and to enable it you'd want to create a symlink to that file from the sites-enabled directory.

like image 152
russell Avatar answered Oct 23 '22 00:10

russell


As @Memes pointed out, I made a mistake in my location block:

location /demos/demo-magento2/ {
  set $MAGE_ROOT /mnt/storage/demo-magento2/;
  set $MAGE_MODE developers;
  include /mnt/storage/demo-magento2/nginx.conf.sample;
}

Should be:

location /demos/demo-magento2/ {
  set $MAGE_ROOT /mnt/storage/demo/demo-magento2/;
  set $MAGE_MODE developers;
  include /mnt/storage/demo/demo-magento2/nginx.conf.sample;
}

The key is that I was missing the demo/ subfolder in the path. The nginx error was actually pretty self-explanatory!

like image 29
ClementParis016 Avatar answered Oct 23 '22 00:10

ClementParis016