静态资源服务

  • 配置静态资源服务前,需要把默认配置注释掉(如下:第36行)
  • 静态服务配置在第38~47
  • server对应的静态文件所在目录,需要读权限,否则访问返回403;本例已处理:$ sudo chmod -R 755 /data
  • 修改完配置,需要重启nginx服务:$ sudo nginx -s reload
  • 可增加错误日志,第41~42
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections  1024;
}

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    # include /etc/nginx/conf.d/*.conf;

    server {
        location / {
            root /data/www;
            access_log /etc/nginx/logs/app_name/access.log
            error_log /etc/nginx/logs/app_name/error.log
        }
        location /images/ {
            root /data;
        }
    }
}
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

参考

上次更新: 8/9/2018, 2:22:06 PM