1. yum 方式安裝nginx
2.我的個人配置文件test.conf 放至目錄:/etc/nginx/conf.d/
3.個人配置文件內容:
server {
 listen 8080;
 client_max_body_size 10240m; # 錄像及文件上傳大小限制
 keepalive_timeout 1000;
 client_header_timeout 1000; #等待客戶端的頭部超時時間為60秒
 client_body_timeout 1000; #等待客戶端的主體超時時間為60秒
 server_name test.qinxiansheng.cn 127.0.0.1 10.2.166.3;
 access_log /var/log/nginx/test.log;
 location /cheng {
 #支持跨域訪問
 add_header Access-Control-Allow-Origin * always;
 add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
 #add_header Access-Control-Allow-Headers 'Origin, X-Requested-With, Content-Type, Accept, Platform, Token';
 add_header Access-Control-Allow-Headers '*';
 add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
 alias /usr/share/nginx/html;
 index reset.html;
 }
}
4. 我的圖片放至目錄: /usr/share/nginx/html/
比如放至了圖片:1.jpg
5. 給圖片增加讀寫權限:chmod 666 1.jpg
root:/usr/share/nginx/html# ll
total 368
-rw-rw-rw- 1 qin qin 141852 Jun 24 09:37 1.jpg
6. 在test.conf中增加如下內容:
location ~ .*\.(gif|jpg|jpeg|png)$ {
 expires 24h;
 #root /usr/share/nginx/html/;#指定圖片存放路徑
 alias /usr/share/nginx/html/;#指定圖片存放路徑
 access_log /tmp/images.log;#日志存放路徑
 proxy_store on;
 proxy_store_access user:rw group:rw all:rw;
 proxy_temp_path /usr/share/nginx/html/;#圖片訪問路徑
 proxy_redirect off;
 #proxy_set_header Host 127.0.0.1;
 client_max_body_size 10m;
 client_body_buffer_size 1280k;
 proxy_connect_timeout 900;
 proxy_send_timeout 900;
 proxy_read_timeout 900;
 proxy_buffer_size 40k;
 proxy_buffers 40 320k;
 proxy_busy_buffers_size 640k;
 proxy_temp_file_write_size 640k;
 #if ( !-e $request_filename)
 #{
 # proxy_pass http://127.0.0.1;#默認80端口
 #}
 }
7. 執行語法和配置檢測: nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
打印上述內容則表示本次修改沒有問題:
8. 執行nginx重載配置的命令:
nginx -s reload
9.在瀏覽器中訪問:nginx所在機器10.2.166.3
http://10.2.166.3/1.jpg
 
