我正在运行一个nginx.conf来运行Magento,这个网站大部分工作,magento是使用php-fpm
运行的。
但是它的某些部分仍然没有工作,我已经尝试了networking上的每一个wiki,博客等。
我的问题是,我有一个JavaScript的CMS页面和块popup,主要是tiny_mce所见即所得编辑器(/js/tiny_mce/plugins/advimage/image.htm等),他们打开一个page not found
。
我不知道该怎么做,所以这个编辑器显示正确。
另外,下载器不显示。
看起来,这些都使用自己的index.php在一个不同的文件夹比根目录,所以我应该改变的索引?
像$document_root/downloader/index.php
?
我强烈建议您阅读并遵循Martin Fjordvald的nginx入门 。
我为Magento使用以下配置。 它不仅工作得很好,还关闭了图像的access_log等,并有一个特殊的php-fpm配置。 请注意,在服务器块中指定了服务器根目录。 几个配置文件在一个位置块内错误地指定它。
Magento的nginx配置文件:(确保相应地替换所有的路径和域名)
server { listen 80; #listen 443 default ssl; server_name DOMAIN.COM; #rewrite requests to www rewrite ^ $scheme://www.DOMAIN.COM$request_uri permanent; } server { listen 80; #listen 443 default ssl; #ssl_certificate /path/to/ssl.crt; #ssl_certificate_key /path/to/ssl.key; server_name www.DOMAIN.COM; # most likely /var/www/... root /path/to/files; include /etc/nginx/restrictions.conf; location / { index index.php; if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png)$") { access_log off; expires max; } try_files $uri $uri/ @handler; } # protect directories location /app/ { deny all; } location /includes/ { deny all; } location /lib/ { deny all; } location /lib/minify/ { allow all; } location /media/downloadable/ { deny all; } location /pkginfo/ { deny all; } location /report/config.xml { deny all; } location /var/ { deny all; } location /var/export/ { # restrict access to admins auth_basic "Restricted"; auth_basic_user_file htpasswd; autoindex on; } location @handler { rewrite ^(.*) /index.php?$1 last; } # include php specific configuration include /etc/nginx/php.conf; }
这是一个php-fpm特定的配置文件,可以截取错误代码并正确分割路径信息,因此您可以访问PHP中正确的路径部分。 由于性能改进,我也使用Unix套接字而不是端口。 另外请注意,您不需要重复已经在fastcgi_params中指定的fastcgi_params。
fastcgi_intercept_errors on; # this will allow Nginx to intercept 4xx/5xx error codes # Nginx will only intercept if there are error page rules defined # -- This is better placed in the http {} block as a default # -- in that virtual host's server block location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # A handy function that became available in 0.7.31 that breaks down # The path information based on the provided regex expression # This is handy for requests such as file.php/some/paths/here/ include fastcgi_params; fastcgi_index index.php; fastcgi_pass unix:/var/run/phpfpm.sock; }
我的fastcgi_params配置文件针对一个小型服务器(<1GB RAM)进行了优化。 一定要根据您的服务器的性能调整你的:
fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200; fastcgi_connect_timeout 90; fastcgi_send_timeout 180; fastcgi_read_timeout 360; fastcgi_buffer_size 1024k; fastcgi_buffers 8 512k; fastcgi_busy_buffers_size 1024k; fastcgi_temp_file_write_size 1024k; fastcgi_intercept_errors on; fastcgi_pass_header *;
我们有magento安装到mydomain.com/store,我们使用nginx的下一个配置:
server { listen <needed ip(s)>:80; server_name mydomain.com; root /www/mydomain; location ~ /\. { deny all; } location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ { access_log off; expires 30d; } location /store/ { fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/store/index.php; fastcgi_param SCRIPT_NAME /store/index.php; fastcgi_index index.php; } location /store/static/ { } location /store/skin/ { } location /store/media/ { } location /store/errors/ { } location ~* /store/errors/.*\.xml$ { deny all; } location ~* /store/errors/.*\.phtml$ { deny all; } location ~* /store/errors/.*\.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME /store/errors$fastcgi_script_name; fastcgi_index index.php; fastcgi_read_timeout 600; } location /store/js/ { } location ~* /store/js/.*\.php$ { fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/store/js$fastcgi_script_name; fastcgi_param SCRIPT_NAME /store/js$fastcgi_script_name; fastcgi_index index.php; fastcgi_read_timeout 600; } }
你必须重写所有的.htaccess规则到ngnix配置才能正常工作。 值得一读http://www.nbs-system.co.uk/blog-2/magento-optimization-howto-en.html