2012-12-15 72 views
0

我正在用fastcgi開發Nginx上的多語言Magento。一切正常,除非我似乎無法像使用Apache一樣獲取URL。如何重寫Magento的多語言SEO URL的Nginx

我想從url中刪除index.php。例如:

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

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

就這樣。

附加信息:

我試圖在管理設置「使用服務器網址重寫」到。這隻適用於英語,即默認,但是,除了在主頁之外,我得到了西班牙語404,

如果我在管理中將「使用Web服務器重寫」設置爲,那麼除了將index.php添加到URL之外,所有內容都可以正常工作。但是,如果我手動刪除URL的index.php頁面仍然會去404。

此外,在Magento管理我有像這樣的基本URL設置:https://www.examplesite.com/es/和{{secure_base_url}} ../皮膚/等。

我有一個文件夾在我的根/ 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; 
    } 
    } 
} 

希望這不是很多信息,但可能需要。我在網上無處不在,我無法理解如何做到這一點。

感謝

回答

1

編輯您的虛擬主機配置文件用於這一領域,並添加以下內容:

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

然後確保Magento的設置是從網址排除的index.php這應該什麼時候發生啓用使用Web服務器重寫

+0

我沒有虛擬主機,因爲它只是一個有兩個存儲視圖的域。我還需要爲此設置一個虛擬主機嗎? – qrs

+0

我在C:\ mba中得到重複的位置「/」... – qrs

+0

我在C:\ mba中得到重複的位置「/」...或者「try_files」指令在C:\ mba ...中重複或未知指令C:\ mba中的「$ uri」...當我嘗試添加此代碼時。我讀過的所有關於虛擬主機的教程都是關於像這樣設置多個域的:http://gerardmcgarry.com/blog/setting-a-virtual-host-nginx如果我嘗試設置虛擬主機,我最終會一個副本。我將如何去解決這個問題,因爲它似乎需要創建一個名爲domain-somewhere.com和另一個domain-somewhere.com/es/的文件。哎呀,我一直打「返回」,它發佈!然後它說:「對不起,你花了五分鐘!」 – qrs

0

即時通訊在您的設置中丟失了一點,但是好的,您必須在nginx中動態地映射您的商店代碼,但不能你有「en」硬編碼。只需包裝所有配置,備份並重新開始。 nginx有點麻煩,不要繼續創建非常錯誤的非標準配置。使其簡單,像每個magento手冊,但一步一步。

+0

是的,我確定有些設置稍微有些偏差,但它似乎運行良好,我得到了一個「禁止規則,客戶端:127.0.0.1」的錯誤。我可以在這裏使用配置:http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/configuring_nginx_for_magento如果你認爲這將有所幫助。我一直在嘗試優化它爲1G的RAM。 – qrs

+0

嗨,你更好從[此配置鏈接](https://github.com/magenx/nginx-config/blob/master/magento/nginx.conf)開始,使用'fastcgi_param HTTPS $ https if_not_empty;',並且nginx與無關內存消耗,對於mysql和php-fpm設置更是如此... – ADM

0

我創建了一個虛擬主機和chaged我的配置是這樣的:

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

這個configuation的問題是三通「下載」的時候點擊它們,不要更改頁面。 NginX,PHP,Magento系統或數據庫中沒有錯誤記錄。

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」,因爲它不符合 「默認」

工作

我打算使用這個:Zoom Full-Page Cache,因爲我嘗試了它,它真的使我的頁面速度有了很大的提高。他說它可以配置爲多語言。它在我的一些頁面上混亂了幾個小地方。我相信這只是因爲我沒有正確地使用「衝孔」。我有很多額外的擴展安裝。

我提到它的原因是我不確定是否應該首先安裝Zoom,因爲在他的網站上他提供了一些代碼添加到Nginx配置中。這就是我從中學習NginX的地方。所以我想我會打開他的縮放,並正確設置一切,然後重新安裝它。不知道真的。

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

它看起來像我可能必須有一個新的域名爲每種語言:

反正我在這個新的配置在這裏注意到了嗎?