【问题标题】:Nginx. Something like drupal in root and Magento in subfolderNginx。根目录中的drupal和子文件夹中的Magento之类的东西
【发布时间】:2015-07-16 06:57:18
【问题描述】:

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

无需任何 nginx 配置即可成功打开 Magento 主页,但链接不起作用。

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

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

根配置:

server {
    listen  80;

        root /var/www/domain;
        index index.php index.html index.htm;
        server_name domain.com;

    location /fe {
        proxy_pass http://domain.com:1234/visualization;
    }

    location / {
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
              root /var/www/domain;
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9$
        location ~ \.php$ {
                #fastcgi_pass 127.0.0.1:9000;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;

                 }

magento 配置

    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
        }

【问题讨论】:

    标签: magento drupal nginx rewrite subdirectory


    【解决方案1】:

    最好的方法是为 magento 使用一些子域,例如 https://shop.yourdomain.com。但是,如果您想将其保留为 http://yourdomain.com/magento,您需要为 Magento 删除单独的 nginx 配置文件并将 /magento/ 位置添加到根配置。我的意思是:

    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 Secure/Unsecure URL。它应该是http://yourdomain.com/magento/ 您可以通过管理面板或直接在数据库(core_config_data 表)中更改它。最后清除缓存并重启Nginx。

    【讨论】:

    • 感谢您的解决方案。我已经尝试过了。换句话说,它的配置合并,对吧?有没有可能有两个配置?有意义吗?
    • 不,这不是配置合并。一个域名不需要 2 个配置。在您的情况下,Magento 放置在子文件夹中,因此在 Nginx 配置中将其描述为 location /subfolder/ ...
    • 是的,但主要问题是根网站属于另一个部门,也许他们需要编辑他们的 nginx 配置。那是因为我想分开。像“不要编辑本节”这样的消息不是一个好主意:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 1970-01-01
    • 2014-02-25
    相关资源
    最近更新 更多