如何在Nginx的子目录中设置Magneto2?

时间:2017-03-01 13:28:48

标签: nginx magento2

目前,我正在尝试设置一个以http://www.example.com/store/作为主页运行的Magento 2站点,但似乎Magento的路由器不知道该子目录。如果不在子目录下,Magento2运行得很好。

以下是我的设置,Wordpress安装在/var/www/wp下,而Magento2安装在/var/www/store下,下面是我的配置:

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

server {
    server_name www.example.com;
    listen 80;
    port_in_redirect off;

    root /var/www/wp;
    index index.html index.php;
    error_page 419 = @magento;

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

    location /store {

        root /var/www; #seems useless, it works the same even if commented.
        index index.php;
        autoindex off;
        charset UTF-8;
        #error_page 404 403 = /store/pub/errors/404.php; #if this line doesn't be commented, it will display a blank page.

        location = /store {rewrite /store /store/index.php last;} 
        location = /store/ {rewrite /store /store/index.php last;}
        location = /store/setup {rewrite /store/setup /store/setup/index.php last;}
        location = /store/setup/ {rewrite /store/setup/ /store/setup/index.php last;}

        location /store/setup {
            location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
                access_log off;
                expires max;
                try_files $uri =404;
            }
            location /store/setup/index.php {return 419;}
        }

        location /store/pub/ {
            location /store/pub/media/ {
                location /store/pub/media/customer/ {deny all;}
                location /store/pub/media/downloadable/ {deny all;}
                location ~ /store/pub/media/theme_customization/.*\.xml$ {deny all;}
                try_files $uri $uri/ /store/pub/get.php?$args;
                location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
                    add_header Cache-Control "public";
                    expires +1y;
                    try_files $uri $uri/ /store/pub/get.php?$args;
                }
                location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
                    add_header Cache-Control "no-store";
                    expires off;
                    try_files $uri $uri/ /store/pub/get.php?$args;
                }
            }
            location /store/pub/static/ {
                expires max;
                location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
                    add_header Cache-Control "public";
                    expires +1y;
                    if (!-f $request_filename) {
                        rewrite ^/store/pub/static/(version\d*/)?(.*)$ /store/pub/static.php?resource=$2 last;
                    }
                }
                location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
                    add_header Cache-Control "no-store";
                    expires off;
                    if (!-f $request_filename) {
                        rewrite ^/store/pub/static/(version\d*/)?(.*)$ /store/pub/static.php?resource=$2 last;
                    }
                }
                if (!-f $request_filename) {
                    rewrite ^/store/pub/static/(version\d*/)?(.*)$ /store/pub/static.php?resource=$2 last;
                }
            }
            location ~ ^/store/pub/errors/.*\.(xml|phtml)$ {deny all;}
            location /store/pub/errors/ {try_files $uri =404;}
            location = /store/pub/cron.php {deny all;}
        }
        location ~ (index|get|static|report|404|503|11)\.php$ { return 419; }
        if (-e $request_filename) {return 403;}
        rewrite /store /store/index.php last;   

    }

    # Cache static files for as long as possible
    location ~*.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|cur)$ {
        expires max;
        log_not_found off;
        access_log off;
    } 

    # Deny public access to wp-config.php
    location ~* wp-config.php {
        deny all;
    }

    location ~ /\. {deny all;}

    location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass fastcgi_backend;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }  

    location @magento {
        root /var/www;
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_pass fastcgi_backend;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

www.example.com/store会返回附件中的内容; error page 键入http://www.example.com/store/setup导致404ed和地址栏变为http://www.example.com/store/setup/index.php/session/unlogin

非常感谢,如果有人能给我一个线索。非常感谢。

0 个答案:

没有答案