Mac 下 Nginx 安装 ngx-fancyindex

ngx-fancyindex 官方说明

ngx-fancyindex 的官方地址有安装说明,我们可以参考官方说明,使用 MacPorts 包管理器直接安装集成了 ngx-fancyindex 的 Nginx ,这样就省去了自己编译 Nginx + ngx-fancyindex 的过程了。

安装

首先安装 MacPorts 包管理器,直接去 MacPorts 官网下载对应的 pkg 文件安装即可。

然后就是使用 MacPorts 安装 Nginx,命令如下:

1
sudo port install nginx

使用 MacPorts 安装 nginx 的过程中会提示安装依赖项:

1
2
3
4
5
6
7
8
9
Computing dependencies for nginx
The following dependencies will be installed:
bzip2
libedit
ncurses
openssl
openssl3
pcre
zlib

直接选 y 安装即可。

nginx 安装完成后,会提示安装的位置:

1
2
3
4
5
6
7
8
9
10
nginx has the following notes:
A set of sample configuration files has been installed in /opt/local/share/nginx/examples.

Additionally, the files nginx.conf, mime.types, fastcgi.conf have been copied to /opt/local/etc/nginx if they didn't exist yet.
Adjust these files to your needs before starting nginx.

A startup item has been generated that will aid in starting nginx with launchd. It is disabled by default. Execute the following command to start
it, and to cause it to launch at startup:

sudo port load nginx

配置 ngx-fancyindex

通过修改 /opt/local/etc/nginx/nginx.conf 文件来修改配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;

server {
listen 8081;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /Users/xxx/Data/Release;
fancyindex on; # 开启 fancyindex
fancyindex_localtime on; # 显示的文件时间为文件的服务器时间
fancyindex_exact_size off; # 显示出文件的大概大小,单位是 KB 或者 MB 或者 GB
fancyindex_name_length 255; # 显示文件名长度,默认是 50
fancyindex_time_format "%Y-%m-%d %H:%M:%S"; # 时间格式
fancyindex_default_sort date_desc; # 默认按日期降序
fancyindex_directories_first off; # 目录显示在最后
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
...