6. nginx中静态服务搭建
静态文件服务搭建¶
nginx.conf配置文件如下
点击查看
user nobody; worker_processes 2; error_log logs/error.log; 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 main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; gzip on; #开启压缩 gzip_min_length 1; #小于1字节不压缩 gzip_comp_level 2; #压缩级别 gzip_types text/plain text/css image/png;#压缩类型 server { listen 8011; server_name 192.168.94.130; location / { alias dlib1/; #这里的alias的意思就是当访问/的时候就相当于访问dlib1目录下的东西,该目录文件放到安装目录/usr/local/nginx下 autoindex on; #生成目录结构(不配置不会生成目录) set $limit_rate 1k; #限制传输速率单位字节,会访问变慢 index index.html index.htm; } } }
检查启动浏览器访问即可,如果文件中包含index.html会解析出来,不包含直接就是目录文件结构