2012-05-30 86 views
2

我有一个Magento店http://example.com,我想保留一个WordPress的博客http://example.com/blog。 我已经安装了博客,一切似乎都很好,但是当记录到Wp-Admin时,我正在为css和js文件获取404,因为其中的仪表板看起来非常难看。 我做错了吗?附上我的nginx的配置文件Magento Wordpress Nginx配置

################################################################################## 
# 
#      example.com 
# 
################################################################################## 
server { 
    listen  80; 
    server_name example.com ; 
    #charset koi8-r; 

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

    location/{ 
     root /usr/share/nginx/html/mebozo-magento.mebozo.com; 
     try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler 
     index index.php index.html index.htm; 
    } 
     location /blog { 
     root /usr/share/nginx/html/mebozo-magento.mebozo.com/blog; 
     try_files $uri $uri/ /blog/index.php; 
     index index.php index.html index.htm; 
     rewrite ^.*/files/(.*) /wp-includes/ms-files.php?file=$2; 
     rewrite ^.*/wp-admin(.*) $1wp-admin/; 


    } 

    location ~* ^.+\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ 
     { 
     root /usr/share/nginx/html/mebozo-magento.mebozo.com/blog; 
     rewrite ^/.*(/.*\.(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$ $1 last; 

     rewrite ^.*/files/(/.*(html|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js))$/wp-includes/ms-files.php?file=$1 last; 

     expires 30d; 
     break; 
     } 

## These locations would be hidden by .htaccess normally 

#location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
#expires 1y; 
#log_not_found off; 
#} 

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

################For Foomen Speedster############### 
#rewrite ^/minify/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last; 
# rewrite ^/skin/m/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last; 

# location /lib/minify/ { 
#  allow all; 
# } 


error_page 404    /404.html; 
    location = /404.html { 
     root /usr/share/nginx/html; 
    } 

#############gzip########### 

     gzip on; # use gzip compression 
     gzip_min_length 1100; 
     gzip_buffers 4 8k; 
     gzip_proxied any; # enable proxy for the fcgi requests 
     gzip_types text/plain text/css application/x-javascript text/javascript application/json; 

    # redirect server error pages to the static page /50x.html 
    # 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root /usr/share/nginx/html; 
    } 

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
    # 
    #location ~ \.php$ { 
    # proxy_pass http://127.0.0.1; 
    #} 
    location @handler { ## Magento uses a common front handler 
     rewrite//index.php; 
    } 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    # 

    location ~ \.php$ { 
     #  if (!-e $request_filename) { rewrite//index.php last; } ## Catch 404s that try_files miss 
     root   /usr/share/nginx/html/mebozo-magento.mebozo.com; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/mebozo-magento.mebozo.com$fastcgi_script_name; 
     include  fastcgi_params; 
    } 

    # deny access to .htaccess files, if Apache's document root 
    # concurs with nginx's one 
    # 
    location ~ /\.ht { 
     deny all; 
    }  
} 

回答

0

我将尝试通过提示我们清理你的nginx的配置文件来解决这个难题。你的* /文件/重写看起来对我来说是有问题的。

不知道你的nginx.conf文件是什么样的,或者你的http {block}是什么样的,我会认为它很干净,而且你正在处理像gzip类型,ssl协议和密码这样的全局设置,额外的标题,等等。我知道你把你​​的gzip包含在你的文件中,但有时在服务器上重复了这一点,却没有意识到它已经设置了一层以上......如果不是,你可以根据需要添加你的gzip。说了这么多,完全读你的conf文件后,我会建议它重写这样的事情:

(注:新的URI的水平位置和@rewrites,并去除多余的根路径定义)

server { 
    listen 80; 
    listen [::]:80; 

    ## SSL CONFIGURATION (can be done here in same file) 
    #listen 443 ssl http2; 
    #listen [::]:443 ssl http2; 
    #ssl_certificate  /etc/nginx/ssl/cert_chain.crt; 
    #ssl_certificate_key  /etc/nginx/ssl/star_example.com.priv.key; 

    # domain name 
    server_name example.com www.example.com; 

    # doc root 
    root /usr/share/nginx/html/mebozo-magento.mebozo.com; 

    ## Logs per vhost 
    access_log  /var/log/nginx/example.com.access.log; 
    error_log  /var/log/nginx/example.com.error.log warn; 

    ## This can also be set in your http block and if it is, it's not needed here. 
    index index.php index.html index.htm; 

    # Adjust upload max file size settings 
    # This value should match your PHP.ini config settings for upload_max_filesize 
    client_max_body_size 50M; # allows file uploads up to 50 megabytes 

    location = /favicon.ico { 
     log_not_found off; 
     access_log off; 
    } 
    location = /robots.txt { 
     allow all; 
     log_not_found off; 
     access_log off; 
    } 

    ## Main Magento location 
    location/{ 
     try_files $uri $uri/ @rewrite; 
    } 

    # Your blog location 
    location /blog/ { 
     try_files $uri $uri/ @rewrite_blog; 
    } 

    # redirect server error pages to the static page /50x.html 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root /usr/share/nginx; 
    } 

    ## These locations are protected 
    location ~ /(app|downloader|includes|pkginfo|var|errors/local.xml)/ { 
     deny all; 
    } 

    ## Images 
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
     expires max; 
     log_not_found off; 
     access_log off; 
     add_header ETag ""; 
    } 

    location =/js/index.php/x.js { 
     rewrite ^(.*\.php)/ $1 last; 
    } 

    # rewrites 
    location @rewrite { 
     rewrite//index.php?$args; 
    } 

    location @rewrite_blog { 
     rewrite /blog/ /blog/index.php?$args; 
    } 

    ## Execute PHP scripts 
    location ~ \.php$ { 
     try_files $uri =404; 
     fastcgi_split_path_info ^(.+\.php)(/.+)$; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     ## Store code with multi store/domain magento instance 
     #fastcgi_param MAGE_RUN_CODE $mage_code; 
     #fastcgi_param MAGE_RUN_TYPE $mage_type; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include fastcgi_params; 
    } 

    # Banned locations (only reached if the earlier PHP entry point regexes don't match) 
    location ~* (\.php$|\.sh$|\.txt$|\.htaccess$|\.git|\.sample$|mage$) { 
     deny all; 
    } 
}