【问题标题】:Runnin magento unde the wordpress as a subdirectory over Nginx将 wordpress 作为 Nginx 上的子目录运行 magento
【发布时间】:2014-12-07 16:00:12
【问题描述】:

我在 Wordpress 下运行 magento(Wordpress 在根目录下,mangento 在子目录“/shop”下)。以前我在 Apache 下运行它,所以在 /shop 文件夹下使用单独的 .htaccess 一切运行良好。

当我在 NginX 上移动服务器时,所有内部 magento URL 都显示 404。请帮我解决这个问题。请建议我如何使用 Wordpress 在 /shop 文件夹下运行 Magento。

这是我的 NginX 配置文件:

server {
listen       80;
server_name  domain.com www.domain.com;

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

error_log           /var/www/logs/error.log;
access_log         /var/www/logs/access.log;

### gZip Setting ###
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
### gZip End ###

location / {
if ($http_host !~ "^www\."){
     rewrite ^(.*)$ http://www.$http_host/$1 redirect;
    }
    try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
    root /usr/share/nginx/html;
}

location /shop/ {
    try_files $uri $uri/ /index.php?$args;
}

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

if (!-e $request_filename)
{
    rewrite ^(.+)$ /index.php?q=$1 last;
}

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
    fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params; ## See /etc/nginx/fastcgi_params
}

}

【问题讨论】:

    标签: magento nginx rewrite


    【解决方案1】:

    我得到了解决方案,这是我的新配置文件:

    server {
    listen   80;
    
    server_name  domain.com www.domain.com;
    
    root   /var/www/html;
    index index.php index.html index.htm;
    
    error_log           /var/www/logs/domain-error-ssl.log;
    access_log         /var/www/logs/domain-access-ssl.log;
    
    ### gZip Setting ###
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    ### gZip End ###
    
    location / {
        if ($http_host !~ "^www\."){
      rewrite ^(.*)$ https://www.$http_host/$1 redirect;
    }
        try_files $uri $uri/ /index.php?$args;
    }
    
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
    
    location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
        rewrite ^(.*.php)/ $1 last;
    }
    
    ### Configuration for shop ###
    location /shop {
        index index.html index.php;
        try_files $uri $uri/ @handler;
        expires 30d;
        if ($uri ~ "^/index.php/admin.*$"){
                rewrite ^/index.php/admin(.*) /admin$1 redirect;
        }
    }
    
    location ~ ^/shop/(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
    location /shop/var/export/ { internal; }
    location @handler { rewrite / /shop/index.php; }
    ### END Configuration for shop ###
    
    location ~ .php$ { ## Execute PHP scripts
        expires        off; ## Do not cache dynamic content
        fastcgi_read_timeout 120;
        #fastcgi_pass   127.0.0.1:9000;
    fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
        #fastcgi_param  HTTPS $fastcgi_https;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params; ## See /etc/nginx/fastcgi_params
    }
    

    }

    【讨论】:

    • 我们使用了类似的东西,但现在有问题,例如 /checkout 和 /customer/account 返回 404 ....
    猜你喜欢
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2018-03-14
    • 2020-12-31
    • 2023-04-09
    • 2016-06-20
    相关资源
    最近更新 更多