Nginx。类似于根目录中的drupal和子文件夹中的Magento

Nginx。类似于根目录中的drupal和子文件夹中的Magento,magento,drupal,nginx,rewrite,subdirectory,Magento,Drupal,Nginx,Rewrite,Subdirectory,在根目录中我有Drupal。在子目录中我有Magento。很可能drupal重写与magento重写重叠 Magento主页在没有任何nginx配置的情况下成功打开,但链接不起作用 我不确定,但我认为要解决这个问题,我需要从drupal路由中排除magento目录。 另一件事是,我不确定是否有正确的magento配置。 根配置: magento配置 最好的方法是为magento使用一些子域,如。但如果您想保留它,您需要删除Magento的单独nginx配置文件,并将/Magento/locati

在根目录中我有Drupal。在子目录中我有Magento。很可能drupal重写与magento重写重叠

Magento主页在没有任何nginx配置的情况下成功打开,但链接不起作用

我不确定,但我认为要解决这个问题,我需要从drupal路由中排除magento目录。

另一件事是,我不确定是否有正确的magento配置。

根配置:

magento配置


最好的方法是为magento使用一些子域,如。但如果您想保留它,您需要删除Magento的单独nginx配置文件,并将/Magento/location添加到根配置中。我的意思是:

location /magento/ {
    root /var/www/domain/magento; #main thing
    index index.html index.php;
    try_files $uri $uri/ @handler;
    expires 30d;
}

location ^~ /magento/app/ { deny all; }
location ^~ /magento/includes/ { deny all; }
location ^~ /magento/lib/ { deny all; }
location ^~ /magento/media/downloadable/ { deny all; }
location ^~ /magento/pkginfo/ { deny all; }
location ^~ /magento/report/config.xml { deny all; }
location ^~ /magento/var/ { deny all; }
location ~ /magento/\.ht { deny all; }

etc.

然后您需要检查Magento安全/不安全URL。应该是,您可以通过管理面板或直接在数据库(核心配置数据表)中进行更改。最后,请清除缓存并重新启动Nginx。

感谢您提供此解决方案。我已经试过了。换句话说,它的配置合并,对吗?有可能有两个配置吗?这有意义吗?不,这不是配置合并。一个域名不需要2个配置。在您的案例中,Magento被放置在子文件夹中,因此在Nginx配置中将其描述为location/subfolder/…是的,但主要问题是,根目录下的网站属于另一个部门,可能他们需要编辑其Nginx配置。那是因为我想分开。像“请勿编辑此部分”这样的消息不是很好的主意:)
    server {
        listen 80;
    ## SSL directives might go here
        server_name domain.com; ## Domain is here twice so server_name_in_redirect will favour the www
        root /var/www/domain/magento;

        location / {
            index index.html index.php; ## Allow a static html file to be shown first
            try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
        # try_files $uri $uri/ /index.php?q=$uri&$args;
            expires 30d; ## Assume all files are cachable
        }

        ## 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 ~ /\.ht { deny all; }

        location /var/export/ { ## Allow admins only to view export folder
            auth_basic "Restricted"; ## Message shown in login window
            auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
            autoindex on;
        }

##        location /.
        location ~ /\.ht { ## Disable .htaccess and other hidden files
            return 404;
        }

        location /api {
            rewrite ^/api/rest /api.php?type=rest last;
        }

        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;
        }

        location ~ .php$ { ## Execute PHP scripts
            if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss

            expires off; ## Do not cache dynamic content
            fastcgi_pass unix:/var/run/php5-fpm.sock;
##          fastcgi_pass 127.0.0.1:8079;
        ##fastcgi_read_timeout 10800s;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
            fastcgi_param MAGE_RUN_TYPE store;
            include fastcgi_params; ## See /etc/nginx/fastcgi_params
        }
location /magento/ {
    root /var/www/domain/magento; #main thing
    index index.html index.php;
    try_files $uri $uri/ @handler;
    expires 30d;
}

location ^~ /magento/app/ { deny all; }
location ^~ /magento/includes/ { deny all; }
location ^~ /magento/lib/ { deny all; }
location ^~ /magento/media/downloadable/ { deny all; }
location ^~ /magento/pkginfo/ { deny all; }
location ^~ /magento/report/config.xml { deny all; }
location ^~ /magento/var/ { deny all; }
location ~ /magento/\.ht { deny all; }

etc.