9

enter image description hereMy actions: I install only: nginx 1.10.1, php7 and mysql 5.6 on ubuntu 14.04. php install: sudo apt-get install -y php7.0-fpm php7.0-common php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-curl php7.0-intl php7.0-xsl php7.0-mbstring php7.0-zip php7.0-bcmath php7.0-iconv php7.0-opcache php7.0-soap php7.0-json php7.0-xml I copy sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/agestor.com. In agestor.com paste:

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

server {  
    listen 443 ssl;
    server_name agestor.com;
    set $MAGE_ROOT /var/www/agestor.com/html;
    set $MAGE_MODE default;
    include /var/www/agestor.com/html/nginx.conf.sample;
}

server {  
    listen 80;
    server_name agestor.com;
    set $MAGE_ROOT /var/www/agestor.com/html;
    set $MAGE_MODE default;
    include /var/www/agestor.com/html/nginx.conf.sample;
}  

And include him: sudo ln -s /etc/nginx/sites-available/agestor.com /etc/nginx/sites-enabled/ But not install magento 2.

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

error.log: 2016/06/21 14:21:35 [error] 13909#13909: *46 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 37.146.123.141, server: agestor.com, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "www.agestor.com" I set up my VPS on this article: magento 2 for ubuntu 14.04

6
  • Check the nginx logs to see what the startup errors are
    – scrowler
    Jun 20, 2016 at 7:14
  • run nginx -t to see whats wrong
    – MagenX
    Jun 20, 2016 at 7:49
  • if you copy-paste configs then something is incomplete, some files or settings just missing.move all configuration, run nginx test
    – MagenX
    Jun 20, 2016 at 8:12
  • I open sudo nano /var/run/php/php7.0-fpm.sock He was empty...
    – Sylon
    Jun 22, 2016 at 2:20
  • Maybe someone will write a short sequence of settings and actions? Please.
    – Sylon
    Jun 22, 2016 at 2:51

3 Answers 3

15

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-domain.com with the following 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

12
  • What have you added or changed in this answer? Can you clarify?
    – scrowler
    Jun 20, 2016 at 7:17
  • I meant please add to your answer :-)
    – scrowler
    Jun 20, 2016 at 7:20
  • 1
    the problem not in nginx config but in "copy-paste" issue, i think something is missing there, and you have to teach them to fix the issue, instead you offer him another copy-paste. this is the never ending story...
    – MagenX
    Jun 20, 2016 at 8:09
  • Unfortunately it does not work. Please write steps after install: nginx, php7, mysql. Maybe I made a mistake.
    – Sylon
    Jun 20, 2016 at 11:02
  • I showed in the issue at the top of the image and error logs.
    – Sylon
    Jun 21, 2016 at 14:52
3

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.

0
1

Late answer... 2023

Example for NGINX configuration files for Magento ver. 2.4.5

File main configuration /etc/nginx/nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        gzip on;

        application/xml+rss text/javascript;

        upstream fastcgi_backend {
            server unix:/var/run/php/php8.1-fpm.sock;
        }
        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

File configuration for domain /etc/nginx/sites-available/domain.com

server {
    listen 443 ssl http2;

    ssl_certificate      /etc/nginx/ssl/domain.com/cert.crt;
    ssl_certificate_key  /etc/nginx/ssl/domain.com/private.key;

    server_name domain.com;

    set $MAGE_ROOT /var/www/html;
    set $MAGE_DEBUG_SHOW_ARGS 0;

    location /blog {
       root /var/www/html;
       index index.php;
       try_files $uri $uri/ /blog/index.php;

       location ~ \.php$ {
            include fastcgi_params;
            fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        }

        location ~* /(?:uploads|files)/.*\.php$ {
            deny all;
        }
    }

    include /var/www/html/nginx.conf;

    index index.html index.htm index.php;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
     }

    location ~ /\.ht {
        deny all;
    }

}

File configuration for service sub-domain /etc/nginx/sites-available/service.domain.com

server {
    listen 443 ssl http2;

    ssl_certificate      /etc/nginx/ssl/domain.com/cert.crt;
    ssl_certificate_key  /etc/nginx/ssl/domain.com/private.key;

    server_name service.domain.com;

    root /var/www/service;

    index index.html index.htm index.php;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
     }

    location ~ /\.ht {
        deny all;
    }
}

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.