1. 程式人生 > >Nginx靜態資源訪問配置

Nginx靜態資源訪問配置

我的Nginx配置所在CentOS6.8上的路徑
/usr/local/nginx/conf/conf.d/odboy.cn.conf
upstream tian-sso-web-main {
	server 192.168.178.110:8081 weight=10;
}
server {
	listen       80;
	server_name www.odboy.cn;
	access_log  logs/www_odboy_access.log  main;
	location ~/tian-sso-web-main {
		proxy_pass http://tian-sso-web-main;
		proxy_redirect off;
		proxy_set_header Host $host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $remote_addr;
		proxy_set_header X-Forwarded-Host $server_name;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		client_max_body_size 50m;
		client_body_buffer_size 128k;
		proxy_connect_timeout 90;
		proxy_send_timeout 90;
		proxy_read_timeout 90;
		proxy_buffer_size 4k;
		proxy_buffers 4 32k;
		proxy_busy_buffers_size 64k;
		proxy_temp_file_write_size 64k ;
		proxy_headers_hash_max_size 51200 ;
		proxy_headers_hash_bucket_size 6400 ;
	}
	location /update/sso{
		alias /tianjun/files/sso;
		autoindex on;
	}
	location / {
		rewrite (.*) http://www.odboy.cn/tian-sso-web-main permanent;
	}
}

以下為靜態檔案配置說明

# 這裡是訪問的路徑,即:http://{server_name}/update/sso
location /update/sso{
	# 關聯的本地目錄
	alias /tianjun/files/sso;
	# 是否自動生成目錄樹(自動索引)
	autoindex on;
}