NGINX虚拟/别名目录来运行商店 [英] NGINX virtual/alias directory to run a store

查看:80
本文介绍了NGINX虚拟/别名目录来运行商店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mysite.com上有一家magento商店

Hi I have a magento store at mysite.com

现在,我想设置一个网址,该网址将在mysite.com/german上运行我的德语网站

Now I want to setup a url that will run my german website at mysite.com/german

使用相同的安装.我已经有一半可以使用的配置,但是我的问题是,主页之外的所有magento URL 404都在这里.这是我当前的配置.

Using the same install. I already have a half working config, but my issue is that beyond the homepage all magento URLs 404. Here is my current config.

server {

    listen 80;

    server_name mysite.com www.mysite.com;

    ####
    #
    #  BELOW THIS LINE IS MY ATTEMPT TO GET mysite.com/german to run from the same directory as mysite.com
    #
    ####


    location ~ /german(.*)\.php($|/) {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /usr/share/nginx/www$1.php;
        fastcgi_param MAGE_RUN_CODE german;
        fastcgi_param MAGE_RUN_TYPE website;        
    }

    location ~ /german(.*) {
        index index.htm index.php;
        autoindex off;
        alias /usr/share/nginx/www$1;
    }

    location ~ /deutch/ {
        index index.htm index.php;
        try_files $uri $uri/ @handler;
    }

旧配置:

    ###
    #
    # THIS BIT I THINK IS THE PART WHICH IS NOT QUITE WORKING, BUT I DON'T KNOW WHAT THE @handler PART DOES
    # 
    ###
    # This redirect is added so to use Magentos
    # common front handler when handling incoming URLs.
    location @handler {
        rewrite / /index.php;
    }

    ####
    #
    # BELOW THIS LINE IS THE ORIGINAL CONFIG WHICH RUNS mysite.com NO PROBLEMS
    #
    ####

    root /usr/share/nginx/www;

    location / {
        index index.htm index.php;
        try_files $uri $uri/ @handler;
    }

    # Deny access to specific directories no one
    # in particular needs access to anyways.
    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; }

    # Allow only those who have a login name and password
    # to view the export folder. Refer to /etc/nginx/htpassword.
    location /var/export/ {
        auth_basic "Restricted";
        auth_basic_user_file htpasswd;
        autoindex on;
    }

    # Deny all attempts to access hidden files
    # such as .htaccess, .htpasswd, etc...
    location ~ /\. {
         deny all;
         access_log off;
         log_not_found off;
    }

    # This redirect is added so to use Magentos
    # common front handler when handling incoming URLs.
    location @handler {
        rewrite / /index.php;
    }

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

    # Handle the exectution of .php files.
    location ~ .php$ {
        if (!-e $request_filename) {
            rewrite / /index.php last;
        }
        expires off;
        fastcgi_pass 127.0.0.1:9000;
        #fastcgi_param HTTPS $fastcgi_https;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param MAGE_RUN_CODE english;
        fastcgi_param MAGE_RUN_TYPE website;
        include fastcgi_params;
    }
}

推荐答案

location ~* \.php$ {
    if (!-e $request_filename) {
        rewrite / /index.php last;
    }
    expires off;
    set $runcode english;
    set $runtype website;
    if ( $request_uri ~* ^/german ) {
            set $runcode german;
    }
    fastcgi_pass 127.0.0.1:9000;
    #fastcgi_param HTTPS $fastcgi_https;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param MAGE_RUN_CODE $runcode;
    fastcgi_param MAGE_RUN_TYPE $runtype;
    include fastcgi_params;
}

这是第1部分,第2部分是确保代码从相同的代码库运行. 一种解决方案是将目录符号链接到根目录,在/usr/share/nginx/www目录中执行以下命令:

That is part 1, part 2 is to ensure the code is run from the same codebase. One solution is to symlink the directory to the root directory, exec the following in the /usr/share/nginx/www directory:

ln -s . ./german

这很卑鄙,但是有效;)

It's filty, but it works ;)

我们使用以下内容重定向到正确的索引文件:

We're using the following to redirect to the correct index file:

location /german {
    if ( -e $request_filename ) {
        break;
    }
    rewrite ^/german(.*)$   /german/index.php last;
}
    #
    #       Redirection of subdirectory php's to their respective php files
    #       
    location ~ .php/ {
        rewrite ^(.*.php)/ $1 last;
    }
    #
    #       Redirect everything else to root path
    #
    location / {
            try_files $uri $uri/ /index.php?$args;
    }

这篇关于NGINX虚拟/别名目录来运行商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆