Magento Nginx 子页面重写
Magento Nginx sub-page rewrites
我正在为 Magento 从 Apache 切换到 Nginx,但似乎无法正确设置和工作。我已经在测试服务器上安装了所有东西,magento 安装顺利,我可以正确访问主页和管理面板,但是如果我从前端导航到任何子页面,URL 会丢失 "index.php" 并给我一个 500 内部服务器错误。例如,如果我尝试 /magento/contacts/ 我会收到 500 错误,但如果我添加 /magento/index.php/contacts/ 它会加载。
我尝试了无数种不同的 nginx 配置,但都没有奏效。我在这里搜索了与同一问题相关的 posts,但没有任何乐趣。我最后的希望是 post 我的配置文件在这里,希望有人能帮忙!
我遵循了这个:https://gist.github.com/tegansnyder/96d1be1dd65852d3e576 信中的教程,除上述问题外一切正常。
如有任何建议,我们将不胜感激!我在这里撕扯我的头发!提前致谢!
我有两个配置文件:
第一个配置文件
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 .;
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;
}
第二个配置文件
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)/ 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
}
请完整阅读此文档: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;
}
}
问题是我的商店在 /var/www/magento。将文件移动到 /var/www,一切都很好 :) 感谢大家的帮助。
我正在为 Magento 从 Apache 切换到 Nginx,但似乎无法正确设置和工作。我已经在测试服务器上安装了所有东西,magento 安装顺利,我可以正确访问主页和管理面板,但是如果我从前端导航到任何子页面,URL 会丢失 "index.php" 并给我一个 500 内部服务器错误。例如,如果我尝试 /magento/contacts/ 我会收到 500 错误,但如果我添加 /magento/index.php/contacts/ 它会加载。
我尝试了无数种不同的 nginx 配置,但都没有奏效。我在这里搜索了与同一问题相关的 posts,但没有任何乐趣。我最后的希望是 post 我的配置文件在这里,希望有人能帮忙!
我遵循了这个:https://gist.github.com/tegansnyder/96d1be1dd65852d3e576 信中的教程,除上述问题外一切正常。
如有任何建议,我们将不胜感激!我在这里撕扯我的头发!提前致谢!
我有两个配置文件:
第一个配置文件
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 .;
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;
}
第二个配置文件
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)/ 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
}
请完整阅读此文档: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;
}
}
问题是我的商店在 /var/www/magento。将文件移动到 /var/www,一切都很好 :) 感谢大家的帮助。