2016-11-28 84 views
0

我是nginx服务器中的新手。NGINX无法加载css

我的服务器是Centos。

我在许多网络上搜索如何使用LEMP设置服务器。 我的网站正在使用.htaccess重写不支持nginx的url,然后我发现try_files可以帮我做到这一点,但CSS无法加载。

> Resource interpreted as Stylesheet but transferred with MIME type 
> text/html: "http://stg-owners.tamahome.jp/style.css". 

我搜索的谷歌,但没有帮助

这里是我的配置

server { 
listen  80; 
server_name localhost; 

#charset koi8-r; 
#access_log /var/log/nginx/log/host.access.log main; 
#root /var/www/owners; 

#auth_basic "Secret Area"; 
#auth_basic_user_file "/etc/nginx/htpasswd/.owners_htpasswd"; 

location/{ 
    alias /var/www/owners/htdocs; 
    index index.php index.html index.htm; 
    include  /etc/nginx/mime.types; 

    location ~ { 
     root   /var/www/owners/htdocs; 
     include  /etc/nginx/mime.types; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     #fastcgi_param PATH_INFO $uri; 
     include  fastcgi_params; 
     try_files $uri $uri/ /index.php?$args; 
    } 

    #location ~ .*\.(css|CSS)$ { 
     #add_header Content-Type text/css; 
     #try_files $uri $uri/ *.css; 
    #} 

    #if ($request_filename ~* ^.*?/([^/]*?)$){ 
     #set $filename $1; 
    #} 

    #if ($filename ~* ^.*?\.css$){ 
     #add_header Content-Type text/css; 
    #} 

    #location ~ \.css$ { 
     #add_header Content-Type text/css; 
    #} 
    #location/{ 
     #if ($script_filename !~ "-f") { 
      #rewrite !\.ico$ /index\.php break; 
     #} 
    #} 
} 

location /admin { 
    alias /var/www/admin; 
    index index.html index.htm index.php; 
} 

location /phpmyadmin { 
    alias /usr/share/phpMyAdmin; 
    index index.php; 
    location ~ ^/phpmyadmin/(.+\.php)$ { 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_split_path_info ^/phpmyadmin/(.+\.php)(.*)$; 
     fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin/$fastcgi_script_name; 
     include  fastcgi_params; 
    } 
    break; 
} 


#error_page 404    /404.html; 

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

这里是的.htaccess

DirectoryIndex index.html index.php bukken.php 

# rewrite関連 
RewriteEngine On 

RewriteRule .*/\.svn/.*/[F] 
RewriteRule \.svn/.*/[F] 

RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule !\.ico$ index\.php [L] 

# php.ini関連 
php_flag session.auto_start 0 
php_flag magic_quotes_gpc 0 
php_value session.use_trans_sid 0 
php_value session.use_cookies 1 
php_value session.use_only_cookie 0 
php_value session.gc_maxlifetime 14400 
php_value upload_tmp_dir /tmp/upload 
php_value post_max_size  32M 
php_value upload_max_filesize 32M 

php_value url_rewriter.tags "a=href,area=href,frame=src,form=,fieldset=,img=src" 

请帮助。 很抱歉,因为我的英文不好

回答

1

你应该使用类似的东西(这只是一个例子):

server { 
listen  80; 
server_name localhost; 

# In fact, it is not needed, it should be included by default in main config 
include  /etc/nginx/mime.types; 

#charset koi8-r; 
#access_log /var/log/nginx/log/host.access.log main; 
#root /var/www/owners; 

#auth_basic "Secret Area"; 
#auth_basic_user_file "/etc/nginx/htpasswd/.owners_htpasswd"; 

location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ { 
    root   /var/www/owners/htdocs; 
    expires 10d; 
} 
location/{ 
    root /var/www/owners/htdocs; 
    index index.php index.html index.htm; 


     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     #fastcgi_param PATH_INFO $uri; 
     include  fastcgi_params; 
     try_files $uri $uri/ /index.php?$args; 

    #location ~ .*\.(css|CSS)$ { 
     #add_header Content-Type text/css; 
     #try_files $uri $uri/ *.css; 
    #} 

    #if ($request_filename ~* ^.*?/([^/]*?)$){ 
     #set $filename $1; 
    #} 

    #if ($filename ~* ^.*?\.css$){ 
     #add_header Content-Type text/css; 
    #} 

    #location ~ \.css$ { 
     #add_header Content-Type text/css; 
    #} 
    #location/{ 
     #if ($script_filename !~ "-f") { 
      #rewrite !\.ico$ /index\.php break; 
     #} 
    #} 
} 

location /admin { 
    alias /var/www/admin; 
    index index.html index.htm index.php; 
} 

location /phpmyadmin { 
    alias /usr/share/phpMyAdmin; 
    index index.php; 
    location ~ ^/phpmyadmin/(.+\.php)$ { 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_split_path_info ^/phpmyadmin/(.+\.php)(.*)$; 
     fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin/$fastcgi_script_name; 
     include  fastcgi_params; 
    } 
    break; 
} 


#error_page 404    /404.html; 

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

所以nginx的将提供静态文件,而无需代理,并使用在/ etc定义的内容类型/ nginx/mime.types

+0

谢谢,它的工作 – user3783161