5

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?

3
  • you say it is located in /mnt/storage/demo/demo-magento2 but in your location block you declare /mnt/storage/demo-magento2/, there is a mismatch already there. correct it already, maybe that's it Commented Jan 19, 2016 at 10:11
  • also it says you have to heve at least Nginx 1.8 or higher Commented Feb 1, 2016 at 12:26
  • @Memes damn, that was it, thanks! (sorry for the late reply btw) Commented Aug 16, 2016 at 8:57

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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!

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.