0

我正在使用 fastcgi 在 Nginx 上开发多语言 Magento。一切正常,除了我似乎无法像使用 Apache 那样获得 URL。

我想从 url 中删除 index.php。例子:

/es/index.php/category.html 到 /es/category.html

也用英文 /index.php/category.html 到 /category.html

就这样。

附加信息:

我试图在管理中将“使用 Web 服务器重写”设置为yes。这有效,但仅适用于英语,即默认值,但随后我得到西班牙语的 404,除了主页

如果我在管理中将 "Use Web Server Rewrites" 设置为no,那么除了将 index.php 添加到 URL 之外,一切正常。但是,如果我从 URL 中手动删除 index.php,页面仍然会转到 404。

此外,在 Magento 管理中,我有这样的基本 URL 设置:https : //www.examplesite.com/es/ 和 {{secure_base_url}}../skin/ 等。

我的根目录 /es/ 中有一个文件夹,其中包含 index.php 的副本,如下所示:

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

Mage::run('es');

这是我的 Nginx 配置:

worker_processes  1;

error_log                           /mba/nginx/logs/error.log;
pid                                 /mba/nginx/logs/nginx.pid;

events {
    worker_connections              2048;
}
http {
    include                         mime.types;
    default_type                    application/octet-stream;
    server_names_hash_bucket_size   64;
    open_file_cache                 max=100 inactive=1m; 
    open_file_cache_valid           20s;
    open_file_cache_min_uses        1;
    open_file_cache_errors          on;
    fastcgi_buffers                 256 4k; 
    ignore_invalid_headers          on; 
    client_header_buffer_size       1k;
    client_body_buffer_size         64k;
    large_client_header_buffers     4 8k;
    client_body_timeout             60;
    client_header_timeout           60;
    keepalive_requests              100;    
    keepalive_timeout               300 300;
    keepalive_disable               msie6;
    send_timeout                    60; 
    max_ranges                      1;  
    reset_timedout_connection       on; 
    sendfile        on; 
    sendfile_max_chunk              512k;
    server_tokens                   off; 
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request "'
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log                      /mba/nginx/logs/access.log  main;

    autoindex off;
    map $scheme $fastcgi_https { ## Detect when HTTPS is used
        default off;
        https on;
    }

    gzip                            on;
    gzip_static                     on;
    gzip_disable                    "MSIE [1-6]\.";
    gzip_vary                       on;
    gzip_comp_level                 2;
    gzip_min_length                 0;
    gzip_proxied                    any;
    gzip_types                      text/plain image/x-icon image/bmp text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    proxy_buffering on;
    #proxy_cache_path               /mba/nginx/proxy levels=1:2 keys_zone=one:15m inactive=7d max_size=1000m;
    proxy_buffer_size               4k;
    proxy_buffers                   100 16k;
    proxy_connect_timeout           60;
    proxy_send_timeout              60;
    proxy_read_timeout              60;
    #include                         /mba/nginx/conf.d/*.conf;

    ##
    # SSL Support
    ##
    map $scheme $fastcgi_https {
    default off;
        https on;
    }

server {
    listen                          80;
    #listen                         443 default ssl;
    expires                         max;
    add_header                      Cache-Control public;   
    #ssl_certificate                /openssl/ssl/www_mybelovedangels_com.crt;
    #ssl_certificate_key            /openssl/ssl/www_mybelovedangels_com.key;
    #access_log                     /mba.nginx.1/mba/nginx/logs/access_log;
    root                            /mba.nginx.1/mba/www;

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
    expires                         +60d;
    log_not_found                   off;
    } 
location / {
    index index.html index.php;
    try_files $uri $uri/ @handler;
    expires +30d;
    deny    192.168.1.1;
    allow   192.168.1.0/24;
    allow   127.0.0.1;
    allow   2620:100:e000::8001;
    deny    all;
    }

    # 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 en;
        fastcgi_param MAGE_RUN_TYPE store;
        include fastcgi_params;
    }
  }
}

我希望这不是太多信息,但可能需要它。我在网上到处都找不到我找不到的地方,我对如何做到这一点一无所知。

谢谢

4

4 回答 4

1

编辑此域的虚拟主机配置文件并添加以下内容:

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

然后确保将 Magento 设置为从 url 中排除 index.php,这在您启用Use Web Server Rewrites时应该发生

于 2012-12-15T21:29:53.713 回答
1

我已经创建了一个虚拟主机并像这样更改了我的配置:

#user              nginx;
worker_processes  1;
error_log         /mba/nginx/logs/error.log;
pid               /mba/nginx/logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
 server_names_hash_bucket_size   64;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request "'
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /mba/nginx/logs/access.log  main;

    sendfile        on;
    autoindex off;
    map $scheme $fastcgi_https { ## Detect when HTTPS is used
        default off;
        https on;
    }

    keepalive_timeout  10;

    gzip  on;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_types      text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;

    # Load config files from the /etc/nginx/conf.d directory
    include /mba/nginx/conf.d/*.conf;

}

和我的虚拟文件,如:

server {
    listen 80;
    server_name myexamplesite.com;
    rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}

server {
    listen 80 default;
## SSL directives might go here
    server_name www.myexamplesite.com *.myexamplesite.com; ## myexamplesite is here twice so server_name_in_redirect will favour the www
    root /mba/www/myexamplesite.com;

    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
        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 /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  /. { ## Disable .htaccess and other hidden files
        return 404;
    }

    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   127.0.0.1:9000;
        fastcgi_param  HTTPS $fastcgi_https;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  MAGE_RUN_CODE en; ## Store code is defined in administration > Configuration > Manage Stores
        fastcgi_param  MAGE_RUN_TYPE store;
        include        fastcgi_params; ## See /etc/nginx/fastcgi_params
    }
}

此配置的问题是单击它们时链接“下载”并且不更改页面。NginX、PHP、Magento 系统或数据库日志中没有错误。

于 2012-12-16T09:56:18.977 回答
0

我有点迷失在你的设置中,但是好的,你必须在 nginx 中动态映射你的商店代码,但现在你已经硬编码了“en”。只需包装所有配置、备份并重新开始。nginx 有点乱,不要继续创建硬错误的非标准配置。让它变得简单,就像按照 magento 手册一样,但要一步一步来。

于 2012-12-16T02:44:09.340 回答
0

ADM

我的新配置是这样工作的:

#user  www-data;
worker_processes  1; ## = CPU qty

error_log  /mba/nginx/logs/error.log;
#error_log  /mba/nginx/logs/error.log  notice;
#error_log  /mba/nginx/logs/error.log  info;

pid        /mba/nginx/logs/nginx.pid;

events {
    worker_connections  1024;
#    use epoll;
       }

http   {
    index index.html index.php; ## Allow a static html file to be shown first
    include      mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    #log_format error403  '$remote_addr - $remote_user [$time_local] '
    #                 '$status "$request"  "$http_x_forwarded_for"';                      

    server_tokens       off;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;

    gzip                on;
    gzip_vary           on;
    gzip_proxied        any;
    gzip_types          text/css application/x-javascript;
    gzip_buffers        16 8k;
    gzip_comp_level     8;
    gzip_min_length     1024;

    keepalive_timeout   15;

    ## Use when Varnish in front
    #set_real_ip_from 127.0.0.1;
    #real_ip_header X-Forwarded-For;

    ## Multi domain configuration
    #map $http_host $storecode { 
       #www.myexamplesite.com 1store_code; ## US main
       #www.myexamplesite.net 2store_code; ## EU store
       #www.domain3.de 3store_code; ## German store
       #www.domain4.com 4store_code; ## different products
       #}

server {   
    listen 80; ## change to 8080 with Varnish
    #listen 443 ssl; 
    server_name www.myexamplesite.com *.myexamplesite.com; ## Domain is here
    root /mba/www;

    access_log  /mba/nginx/access.log  main;

    ## Nginx will not add the port in the url when the request is redirected.
    #port_in_redirect off; 

       ## SSL directives go here
       ##ssl_certificate = cat server.crt bundle.ca.crt >> www_server_com.chained.crt
       #ssl_certificate     /etc/ssl/certs/www_server_com.chained.crt; 
       #ssl_certificate_key /etc/ssl/certs/server.key;

       #ssl_session_cache shared:SSL:15m;
       #ssl_session_timeout 15m;

       #ssl_protocols             SSLv3 TLSv1;
       #ssl_ciphers               HIGH:!ADH:!EXPORT56;
       #ssl_prefer_server_ciphers on;

    ## Server maintenance block. insert dev ip 1.2.3.4 static address www.whatismyip.com
    #if ($remote_addr !~ "^(1.2.3.4|1.2.3.4)$") {
        #return 503;
        #}

        #error_page 503 @maintenance;
        #error_page 403 /403.html;  

    #location @maintenance {
        #rewrite ^(.*)$ /error_page/503.html break;
        #internal;
        #access_log off;
        #log_not_found off;
        #}

    #location = /403.html {
        #root /var/www/html/error_page;
        #internal;
        #access_log   /var/log/nginx/403.log  error403;
        #}

    location / {
        try_files $uri $uri/ @handler;
        }

    ## These locations would be hidden by .htaccess normally
    location ~ (/(app/|includes/|/pkginfo/|var/|errors/local.xml)|/\.svn/|/.hta.+) {
        deny all;
        #internal;
        }

    ## Protecting /admin/ and /downloader/   1.2.3.4 = static ip addresses (www.whatismyip.com)
    #location /downloader    { allow 1.2.3.4; allow 1.2.3.4; deny all; rewrite ^/downloader/(.*)$ /downloader/index.php$1;} 
    #location /admin         { allow 1.2.3.4; allow 1.2.3.4; deny all; rewrite / /@handler;}   

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
        }

    location @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
        add_header X-Config-By 'MagenX -= www.magentomod.com =-';
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        #fastcgi_param  MAGE_RUN_CODE $storecode; ## Store code with multi domain
        fastcgi_param  MAGE_RUN_CODE en; 
        fastcgi_param  MAGE_RUN_TYPE store;
        include        fastcgi_params; ## See /etc/nginx/fastcgi_params
        }
    }
}

MAGE_RUN_CODE我仍然必须添加“en”,因为它不适用于“default”

我打算使用这个:Zoom Full-Page Cache,因为我试过了,它确实大大提高了我的页面速度。他说它可以配置为多语言。它弄乱了我的一些页面上的一些小地方。我确定这只是因为我没有正确地“打孔”:)。我安装了很多额外的扩展。

我提到它的原因是我不确定我是否应该先安装 Zoom,因为在他的网站上,他提供了一些代码来添加到您的 NginX 配置中。那是我了解 NginX 的地方。所以我想我会卸载他的 Zoom 并正确设置所有内容然后重新安装它。真不知道。

无论如何,我在这个新配置中注意到:

#map $http_host $storecode { 
   #www.myexamplesite.com 1store_code; ## US main
   #www.myexamplesite.net 2store_code; ## EU store
   #www.domain3.de 3store_code; ## German store
   #www.domain4.com 4store_code; ## different products
   #} 

看起来我可能必须为每种语言设置一个新域名?

于 2012-12-16T19:48:16.437 回答