skip to Main Content

I want to do nginx setup for handing two project with same domain.

Example domain: example.com

  • Angular project should run with example.com
  • magento2 project should run with example.com/shop

I tried the code below, but its not working.

location /shop {
    alias /var/www/www.example.com/shop/;
    index index.html;
    try_files $uri $uri/
    autoindex on;
}

Can please someone help me to do this.

2

Answers


  1. You can start with the following config to serve your Applications:

    server {
        listen       80;
        server_name  example.com;
    
        location / {
            root /path/to/your/generated/angular/resources;
            try_files $uri$args $uri$args/ /index.html;
        }
    
        location /shop {
            root /path/to/shop/;
            index index.html;
            try_files $uri $uri/;
        }
    }
    

    I’m not 100% sure if the shop route will work. Maybe you need to configure php to serve it. Therefore you can follow this official example.

    If you want to serve also to www.example.com you can set server_name *.example.com (docs).

    Login or Signup to reply.
  2. You should use official NGINX configuration sample as provided here.

    Naturally, you will prefix all the Magento 2 locations with /shop/, for your specific case.

    So you will end up with this kind of config:

    server {
        listen       80;
        server_name  example.com;
    
        location / {
            root /path/to/your/generated/angular/resources;
            try_files $uri$args $uri$args/ /index.html;
        }
        # Magento 2 directives start here...
        location ~* ^/shop/setup($|/) {
            # ...
        }
        # The rest of Magento 2 directives...
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search