Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> 電腦軟件教程 >> 服務器技術 >> 關於服務器 >> nginx資源定向css js路徑問題

nginx資源定向css js路徑問題

日期:2017/2/8 10:11:58      編輯:關於服務器

今天做項目,學學nginx發現還不錯,速度還可以,但是CSS JS確無法使用,原來nginx配置時需要對不同類型的文件配置規則,真是很郁悶,不過想想也還是很有道理。問題解決後,把配置貼上來分享。
#user nobody;
worker_processes 1;

error_log logs/error.log;

pid logs/nginx.pid;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

access_log logs/access.log ;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 8081 default;
server_name localhost;

charset utf-8;

location / {
index index.php;
if (!-e $request_filename) {
#rewrite ^/myapp/(.*\.(css|js|jpg|gif|png))$ /$1 last;
rewrite ^/(.*)$ /index.php/$1;
break;
}
}

location ~ .+\.php($|/) {
set $script $uri;
set $path_info "/";
if ($uri ~ "^(.+\.php)(/.+)") {
set $script $1;
set $path_info $2;
}
include fcgi.conf;
root D:\Apache2.2\htdocs\myblog;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php?IF_REWRITE=1;

fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root/$script;
fastcgi_param SCRIPT_NAME $script;
}

location ~* .(jpg|gif|png|js|css)$ {
root D:\Apache2.2\htdocs\myblog;
if (-f $request_filename) {
expires max;
break;
}
}

}

}

Copyright © Windows教程網 All Rights Reserved