这是我使用nginx做的第一个需求:通过浏览器访问本地mac某一个目录下的内容(支持中文噢):
在 nginx/servers 下添加配置文件:localhost.conf(可随便定义),内容如下:
### 浏览器浏览本地目录http://localhost/ server { listen 80;# 确定80端口没有被占用哦,也可以自定义其他端口号 server_name localhost; # access_log /var/log/nginx/access.log; # location / { # index index.php index.html index.htm; # } # location /Users/lifangyu { # autoindex on; # } location / { root /Users/lifangyu; # //指定实际目录绝对路径; charset utf-8,gbk; autoindex on; # //开启目录浏览功能; autoindex_exact_size off; # //关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b; autoindex_localtime on; # //开启以服务器本地时区显示文件修改日期! } } #### ==========================
重启nginx,在浏览器http://localhost/ 看到如下