Nginx配置静态资源访问
编辑nginx.conf
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root /home/html; index index.html index.htm; } location ~ .*.(gif|jpg|jpeg|png)$ { expires 24h; root /usr/paidroom/pic;#指定图片存放路径,绝对路径 access_log /var/log/paidroom/pic.log;#日志存放路径,绝对路径 proxy_store on; proxy_store_access user:rw group:rw all:rw; proxy_temp_path /usr/paidroom/pic;#图片访问路径,绝对路径 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端口 } } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
然后
/usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
systemctl restart nginx
上一篇:
通过多线程提高代码的执行效率例子