Nginx 上的 Magento - 配置

发布于 2024-12-07 20:48:57 字数 436 浏览 1 评论 0原文

我正在编写用于运行 Magento 的 nginx.conf,该网站大部分工作正常,magento 使用 php-fpm 运行。

但它的某些部分仍然无法正常工作,我已经尝试了网络上的每个维基、博客等。

我的问题是,只要我在 CMS 页面和块上弹出 Javascript,主要是tiny_mce WYSIWYG 编辑器(/js/tiny_mce/plugins/advimage/image.htm 等),它们就会打开一个找不到页面< /代码>。

我不知道应该做什么才能使该编辑器正确显示。

另外,下载器不显示。

似乎每个都在与 root 不同的文件夹中使用自己的 index.php ,所以我应该将索引更改为该文件夹吗?

就像$document_root/downloader/index.php

I'm working on an nginx.conf for running Magento, the site mostly works, magento is run using php-fpm.

But some parts of it are still not working, and I've tried every wiki, blog, etc around the web.

My problem is that where ever I have a Javascript pop-up on CMS pages and blocks, mainly the tiny_mce WYSIWYG editor, (/js/tiny_mce/plugins/advimage/image.htm etc) they open a page not found.

I don't know what should I do so this editor displays correctly.

Also, the downloader doesn't display.

It seems that each of these use its own index.php inside a different folder than root, so should I change the index to that?

like $document_root/downloader/index.php ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

岁月流歌 2024-12-14 20:48:57

我强烈建议您阅读并遵循 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 *;

I HIGHLY suggest you read and follow the nginx primer by Martin Fjordvald.

I use the following configuration for Magento. It not only works great, it also turns off access_log for images, etc. and has a special php-fpm configuration. Please note that the server root is specified within the server block. Several configuration files incorrectly specify it within a location block.

Magento nginx configuration file:
(Be sure to replace all paths and domain names accordingly)

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

This is a php-fpm specific configuration file which intercepts error codes and splits the path info correctly so you have access to the correct path parts in PHP. I also use a Unix socket rather than a port due to performance improvements. Also note that you don't need to repeat the fastcgi_params already specified in 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;
}

My fastcgi_params configuration file is optimized for a small server (<1GB RAM). Be sure to adjust yours according to your server's performance:

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 *;
过潦 2024-12-14 20:48:57

我们已将 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;
    }
}

We have magento installed to mydomain.com/store, and we use next config for 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;
    }
}
泪之魂 2024-12-14 20:48:57

你必须将所有 .htaccess 规则重写为 ngnix 配置才能使其正常工作。值得阅读 http://www.nbs- system.co.uk/blog-2/magento-optimization-howto-en.html

you have to rewrite all .htaccess rules to ngnix configuration to get this working. Worth to read http://www.nbs-system.co.uk/blog-2/magento-optimization-howto-en.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文