2016-11-28 122 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