0

我正在尝试在服务器上安装 magento。这是我的 Vhost 文件。

server {
    listen 80;
    ## SSL directives might go here
    server_name development.magento.in ; ## Domain is here twice so server_name_in_redirect will favour the www
    root /var/www/devcode/;

    client_max_body_size 2M;

    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 365d; ## Assume all files are cachable
    }

    if ($request_uri = /index.php) {
            rewrite ^ http://$host? permanent;
    }

    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 /shell/              { deny all; }
    location /downloader/         { deny all; }
    location /cron.php            { deny all; }

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

    location  /. { ## Disable .htaccess and other hidden files
            return 404;
    }

    location @handler { ## Magento uses a common front handler
        rewrite / /index.php;
    }

    # serve static files directly

    location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|html|txt)$ {
        # root /var/www/devcode/skin/; # I tried to added to this also but never worked
        access_log        off;
        expires           30d;
    }

location ~ \.php$
{
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_read_timeout 300;
}

}

所以通过这个配置 Nginx 显示403 用于 Css 和 js 和 Images。有趣的是,如果我删除它显示404的提供静态文件的部分。我已经尝试过 Stackoverflow 上的所有帖子。这是我的媒体和皮肤目录权限的样子

drwxr-xr-x. 23 nginx  nginx   4096 Mar 22 14:32     media
drwxr-xr-x.  5 nginx  nginx   4096 Mar 13 03:45     skin

任何帮助或提示都将受到高度尊重!


编辑

我的新配置文件是这样的:

server {
    listen 80;
    ## SSL directives might go here
    server_name development.magento.in ; ## Domain is here twice so server_name_in_redirect will favour the www
    root /var/www/devcode/;

    index   index.html index.php; ## Allow a static html file to be shown first

    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    include        /etc/nginx/fastcgi_params;

    access_log /var/log/nginx/development.access.log ;
    error_log  /var/log/nginx/development.error.log ;

    client_max_body_size 2M;

    location / {
            try_files $uri $uri/  /index.php?$args;   #@handler; ## If missing pass the URI to Magento's front handler
            expires 365d; ## Assume all files are cachable
    }

    if ($request_uri = /index.php) {
            rewrite ^ http://$host? permanent;
    }

    location ^~ /(app|includes|lib|media/downloadable|pkginfo|var)/ { internal; }
    location /var/export/ { internal; }

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

    location  /. { ## Disable .htaccess and other hidden files
            return 404;
    }

    # serve static files directly
    location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|html|txt)$ {
        access_log        off;
        expires           30d;
    }

    location ~ \.php$
    {
        fastcgi_pass 127.0.0.1:9000;

        fastcgi_index index.php;
        fastcgi_param MAGE_RUN_CODE default;
        fastcgi_param MAGE_RUN_TYPE store;
        fastcgi_read_timeout 300;
    }

 }

现在我以前的问题是固定的。但现在我无法让我的网站运行。我检查了它说的 access.logHTTP 200 OK但 index.php 没有收到任何请求。

4

1 回答 1

2

您可以简单地对静态文件使用别名指令:

location /skin {
    alias /var/www/devcode/skin;
    access_log        off;
    expires           30d;
}

或更明确地

location /skin/ {
    alias /var/www/devcode/skin/;
    access_log        off;
    expires           30d;
}

(请参阅末尾的正斜杠差异..)

好吧,您实际上也可以使用指令来做到这一点,但是最后一个正斜杠太多了。alias查看和之间root 区别。我仍然建议使用alias,而不是root因为它有明显的理由提供静态服务并且仅在location级别上支持。

不管我的回答如何,我会说这个配置看起来像是来自 apache 重写逻辑,而不是一个真正优化的 nginx 风格。您可能希望将您的静态内容分开,如上所示,放在不同的子文件夹中。那么您可能还想知道为什么If is Evil@handler您可以尝试文件,而不是重写:

location @handler { ## Magento uses a common front handler
    try_files       $uri $uri/ /index.php?$args;
}

对于 s,我想不出一个更聪明的主意deny all。但是,我会将public文件夹中的 php 和静态内容分开并将其定义为 a root,首先将这些denys 排除在外。请注意,如果其中一些建议与您的特定需求相冲突,它们可能听起来毫无意义。

于 2013-03-22T21:10:39.553 回答