2015-01-07 57 views
0

我正在從Apache切換到Nginx的Magento過程,但似乎無法讓它設置和正常工作。我在測試服務器上安裝了所有軟件,並且magento安裝正常,我可以正確訪問主頁和管理面板,但是如果我導航到前端的任何子頁面,URL將丟失「index.php」,並且給我一個500內部服務器錯誤。例如,如果我嘗試/ magento/contacts /我得到一個500錯誤,但如果我添加/magento/index.php/contacts/它加載。Magento Nginx子頁面重寫

我已經嘗試了無數不同的nginx配置,但都沒有工作。我在這裏瀏覽了關於同一個問題的帖子,但沒有喜樂。我最後的希望是在這裏發佈我的配置文件,並希望有人能幫助!

我按照這個:https://gist.github.com/tegansnyder/96d1be1dd65852d3e576教程的信件和一切工作很好,除了上面的問題。

任何建議將非常感謝!我在這裏把我的頭髮撕掉!提前致謝!

我有兩個配置文件:

FIRST CONFIG文件

server { 
server_name 192.121.166.136; 
access_log /var/log/nginx/access.log main; 
error_log /var/log/nginx/error.log info; 

# 504 is a PHP timeout and must be static 
# 502 is momentary during a PHP restart and should be treated like maintenance 
# other 50x errors are handled by Magento 
error_page 502 504 /var/www/magento/504.html; 

listen 80; 
#listen 443 ssl; 

# if you are using a load balancer uncomment these lines 
# header from the hardware load balancers 
#real_ip_header X-Forwarded-For; 
# trust this header from anything inside the subnet 
#set_real_ip_from X.X.X.1/24; 
# the header is a comma-separated list; the left-most IP is the end user 
#real_ip_recursive on; 

# ensure zero calls are written to disk 
client_max_body_size   16m; 
client_body_buffer_size  2m; 
client_header_buffer_size  16k; 
large_client_header_buffers 8 8k; 

root /var/www/; 
index index.php; 

fastcgi_read_timeout 90s; 
fastcgi_send_timeout 60s; 

# ensure zero calls are written to disk 
fastcgi_buffers 512 16k; 
fastcgi_buffer_size 512k; 
fastcgi_busy_buffers_size 512k; 

# remove the cache-busting timestamp 
location ~* (.+)\.(\d+)\.(js|css|png|jpg|jpeg|gif)$ { 
    try_files $uri $1.$3; 
    access_log off; 
    log_not_found off; 
    expires 21d; 
    add_header Cache-Control "public"; 
} 

# do not log static files; regexp should capture alternate cache-busting timestamps 
location ~* \.(jpg|jpeg|gif|css|png|js|ico|txt|swf|xml|svg|svgz|mp4|ogg|ogv)(\?[0-9]+)?$ { 
    access_log off; 
    log_not_found off; 
    expires 21d; 
    add_header Cache-Control "public"; 
} 

# Server 
include main.conf; 
include security.conf; 

} 

第二CONFIG文件

rewrite_log on; 

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

location @handler { 
rewrite//index.php; 
} 

## force www in the URL 
if ($host !~* ^www\.) { 
#rewrite/$scheme://www.$host$request_uri permanent; 
} 

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

location /media/catalog/ { 
expires 1y; 
log_not_found off; 
access_log off; 
} 

location /skin/ { 
expires 1y; 
} 

location /js/ { 
access_log off; 
} 

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 

# for this tutorial we are going to use a unix socket 
# but if HHVM was running on another host we could forego unix socket 
# in favor of an IP address and port number as follows: 
#fastcgi_pass 127.0.0.1:8080; 

fastcgi_pass unix:/var/run/hhvm/sock; 

fastcgi_index index.php; 
#fastcgi_param HTTPS $fastcgi_https; 
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

# if you need to explictly specify a store code for Magento do it here 
# this is useful if you are running multiple stores with different hostnames 
#fastcgi_param MAGE_RUN_CODE default; 
#fastcgi_param MAGE_RUN_TYPE store; 

include fastcgi_params; ## See /etc/nginx/fastcgi_params 

fastcgi_keep_conn on; #hhvm param 
} 

回答

0

問題是我的商店在/ var/www/magento中。將文件移動到/ var/www,一切都很好:)感謝幫助的人。

0

請有此文件的完整閱讀:http://info.magento.com/rs/magentocommerce/images/MagentoECG-PoweringMagentowithNgnixandPHP-FPM.pdf在這裏你可以找到一個基本專門爲Magento配置的ngnix配置:

server { 
    listen 80 default; 
    server_name magento.lan www.magento.lan; # like ServerName in Apache 
    root /var/www/magento; # document root, path to directory with files 
    index index.html index.php; 
    autoindex off; # we don’t want users to see files in directories 
    location ~ (^/(app/\|includes/\|lib/\|/pkginfo/\|var/\|report/config. 
xml)\|/\.svn/\|/\.git/\|/.hta.+) { 
    deny all; #ensure sensitive files are not accessible 
} 
location/{ 
    try_files $uri $uri/ /index.php?$args; # make index.php handle requests for 
/
    access_log off; # do not log access to static files 
    expires max; # cache static files aggressively 
} 
location \~\* \.(jpeg\|jpg\|gif\|png\|css\|js\|ico\|swf)$ { 
    try_files $uri $uri/ @proxy; # look for static files in root directory and 
    ask backend if not successful 
    expires max; 
    access_log off; 
} 
location @proxy { 
    fastcgi_pass fpm_backend; # proxy everything from this location to backend 
} 
location \~\.php$ { 
    try_files $uri =404; # if reference to php executable is invalid return 404 
    expires off; # no need to cache php executable files 
    fastcgi_read_timeout 600; 
    fastcgi_pass fpm_backend; # proxy all requests for dynamic content to 
    # backend configured in upstream.conf 
    fastcgi_keep_conn on; # use persistent connects to backend 
    include fastcgi_params; 
    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; 
    } 
} 
+0

我已經讀過,看起來像其他任何文章,並嘗試過多個不同的配置文件和位置的變化,但似乎沒有工作。如果我關閉magento管理面板中的web服務器重寫,那麼一切正常,但顯然index.php被添加到每個網址。這讓我瘋狂,我可能會回到apache! – treborb

+0

仍然沒有任何東西在你的配置中,代表''位置/ {/ /index.php $ uri $ uri//index.php?$ args;'這是最靠近''RewriteRule。* index.php [L]'的陰影。因爲Magento和大多數PHP框架一樣,並且像構建它的ZF一樣使用index.php來處理所有的請求。 –