1

I am installing Magento 2 into a subdirectory beside the main installation. I would like to configure the subdirectory named "test". However, when I try to access localhost/test to enter the setup page, it just tells:

localhost redirected you too many times. Try clearing your cookies. ERR_TOO_MANY_REDIRECTS.

Here is my NGINX config :

server {
    listen 80 reuseport;
    server_name localhost;

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

    set $MAGE_ROOT /var/www/magento2;
    root $MAGE_ROOT/pub;

    ## Magento Setup Tool
    include conf_m2/setup.conf;

    # Deny all internal locations also default phpmyadmin
    location ~ ^/(app|bin|var|tmp|phpserver|vendor|magento_version|php[mM]y[aA]dmin|pma)/? { deny all; }

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    ## Static location
    include conf_m2/assets.conf;

    location @static { rewrite /static/(version\d*/)?(.*)$ /static.php?resource=$2 last; }
    location @media { try_files $uri $uri/ /get.php$is_args$args; }

    ## Process php files (strict rule, define files to be executed)
    location ~ (index|health_check|get|static|report|404|503)\.php$ {
        try_files $uri =404;

        include conf_m2/php_backend.conf;
        fastcgi_cache microcache;
        fastcgi_cache_key $scheme|$host|search|$arg_q;
        fastcgi_cache_valid 200 301 302 2h;
        fastcgi_cache_use_stale updating error timeout invalid_header http_500;
        fastcgi_pass_header Set-Cookie;
        fastcgi_pass_header Cookie;
        fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
    }

    ###Here is the directory I want to installed another magento 2, but it now works
    rewrite ^/test /test/$1 permanent;
    location /test {
        try_files $uri /$uri/index.php?$args;
        index index.php index.html index.htm;
    }
    rewrite ^/test/admin /test/admin/$1 permanent;
}
1
  • how did u resolve this ? Commented Jan 28, 2019 at 19:33

2 Answers 2

1

I'm no nginx expert but this rewrite ^/test /test/$1 permanent; suspiciously looks like an endless loop.

Why are you doing this? Just create a subdirectory in /var/www/ like /var/www/test and install Magento there.

0

You can try with below code in your nginx configuration file.

location /test/ {
    index index.html index.php;
    try_files $uri $uri/ rewrite /test /test/index.php?$args;
    expires 30d;
}

OR

location /test/ {
    index index.html index.php;
    try_files $uri $uri/ @testhandler;
    expires 30d;
}

location @testhandler {
    rewrite / /test/index.php;
}

I hope this will work for you.

3
  • proper solution = installation into its own home directory. no need to change or rewrite anything. just copy nginx config.
    – MagenX
    Commented Nov 24, 2019 at 14:55
  • @MagenX Have you tried with adding the .htaccess file in your test directory? Also, have you checked with adding the RewriteBase /test/ in your .htaccess file as per this prnt.sc/q1khla screenshot? Commented Nov 25, 2019 at 4:41
  • nginx not working with htaccess. multiple installations into nested folders is a very bad idea...
    – MagenX
    Commented Nov 25, 2019 at 10:16

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.