3
  • Magento 1.9.2.1
  • Nginx 1.8.1

I'm trying to set up a Magento shop, a development server with Nginx for further change.

Currently, it runs on a server with Apache.

Developing I have no problems with redirects. The frontend works well. I used to access the dashboard http: //www.domain.tld/index.php/admin/

But it does not work on my Nginx installation.

If you use http://www.domain.tld/admin/ it asks for my user and password, but then I redirected to a page http://www.domain.tld//index.php/admin/admin/dashboard/index/ giving a 404 error.

server {
    listen      x.xxx.xxx.x:80;
    server_name domain.es www.domain.es;
    root        /home/user/web/domain.es/public_html;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/domain.es.log combined;
    access_log  /var/log/nginx/domains/domain.es.bytes bytes;
    error_log   /var/log/nginx/domains/domain.es.error.log error;

    location / {

        # START Tamaniut
        try_files /maintenance.html $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
        expires 30d; ## Assume all files are cachable
        # END tamainut

        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
        }

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    127.0.0.1:9002;
            fastcgi_index   index.php;
            include         /etc/nginx/fastcgi_params;
        }
    }

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;

    location /error/ {
        alias   /home/user/web/domain.es/document_errors/;
    }

    #START tamainut
    #location ~* "/\.(htaccess|htpasswd)$" {
    #    deny    all;
    #    return  404;
    #}

    ##
    # dont log robots.txt requests
    ##
    location /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    ## These locations would be hidden by .htaccess normally
    location ^~ /app/                { deny all; }
    location ^~ /includes/           { deny all; }
    location ^~ /lib/                { deny all; }
    location ^~ /media/downloadable/ { deny all; }
    location ^~ /pkginfo/            { deny all; }
    location ^~ /report/config.xml   { deny all; }
    location ^~ /var/                { deny all; }
    location /var/export/            { deny all; }

    # deny htaccess files
    location ~ /\. {
        deny  all;
        access_log off;
        log_not_found off;
    }

    #This @handler it's on several tips on stackExchange, Magento Exchange, but when try restart get: "named location "@handler" can be on the server level only"
    #location @handler { ## Magento uses a common front handler
    #    rewrite / /index.php;
    #}

    location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
        rewrite ^(.*.php)/ $1 last;
    }

    rewrite ^/minify/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
    rewrite ^/skin/m/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
    # END Tamainut
    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     /etc/nginx/conf.d/webmail.inc*;

    #include     /home/user/conf/web/nginx.naturjoya.es.conf*;
}

2 Answers 2

1

@handler is missing in your config. Try the following config. Update root and fastcgi_pass according to your environment.

server {   
    listen      x.xxx.xxx.x:80;
    server_name domain.es www.domain.es;

    root /home/user/web/domain.es/public_html;
    index index.php;
    location = /js/index.php/x.js {
        rewrite ^(.*\.php)/ $1 last;
    }

    ## Main Magento @location
    location / {
       try_files $uri $uri/ /index.php?$args;
    }


    ## These locations are protected
    location ~ /(app|var|downloader|includes|pkginfo)/ {
        deny all;
    }

    ## Images
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
        access_log off;
        add_header ETag "";
    }

    ## Fonts
    location ~* \.(swf|eot|ttf|otf|woff|woff2)$ {
        expires max;
        log_not_found off;
        access_log off;
        add_header ETag "";
        add_header Access-Control-Allow-Origin "*";
        add_header Cache-Control "public";
    }


    ## Execute PHP scripts
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass    127.0.0.1:9002;
        fastcgi_buffers 1024 4k;

        fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
        fastcgi_param  PHP_VALUE "memory_limit=768M \n max_execution_time=600";
        fastcgi_read_timeout 600s;
        fastcgi_connect_timeout 600s;

        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;

    }

}
0

change your php{} block rule to more simple and clear for your self:

location ~ \.php$ {
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        try_files $uri =404;
        fastcgi_pass    127.0.0.1:9002;
        fastcgi_index   index.php;
        include         /etc/nginx/fastcgi_params;
        }
1

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.