How to configure nginx for Magento 2?

Magento2 contains Nginx config nginx.conf.sample that can be included in you server section. Let's try with minimal configuration;

You need to modify /etc/nginx/sites-available/my-domen.com with content

upstream fastcgi_backend {
    # socket
    # server unix:/var/run/php5-fpm.sock;
   server   unix:/var/run/php/php7.0-fpm.sock;
    # use tcp connection
    #  server  127.0.0.1:9000;

}
server {
    listen 80;
    server_name www.my-domen.com;
    return 301 $scheme://www.my-domen.com$request_uri;
}

server {
    listen 80 reuseport;
    server_name my-domen.com;

    set $MAGE_ROOT /var/www/my-domen.com/html;

   set $MAGE_MODE developer;
#    set $MAGE_MODE default;
#    set $MAGE_MODE production;

    include /var/www/my-domen.com/html/nginx.conf.sample;
    fastcgi_read_timeout 3000;
}

and then add other settings do not relate to Magento


you need to run nginx -t to see whats missing.

anyway i think you forgot to move other config files, we have installer for this https://raw.githubusercontent.com/magenx/Magento-nginx-config/master/m2_config_install.sh

this will take all nginx configuration files from our repository and copy them to your nginx folder.

Tags:

Nginx

Magento2