随着项目的跟近,与nginx打的交道越来越多,现将遇到的问题记录如下:

相对路径

在进行路径定义时,是否可以使用相对路径?

NO 绝对不能够使用相对路径

日志

# 根级别error_log  /var/logs/error.log warn;http {    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                      '$status $body_bytes_sent "$http_referer" '                      '"$http_user_agent" "$http_x_forwarded_for"';    # http级别    access_log  /var/logs/access.log  main;        server {        listen       8010;        server_name  127.0.0.1 localhost;                # server级别        error_log /var/logs/8010/access.log info;    }}

注意 1. 一定要用绝对路径。2. 如果日志没有马上显示,使用nginx -s reload来重启服务。3. 出现问题一定要看日志

root与alias

访问:attachment时,访问/api/attachment:

    # 附件    location /attachment/ {       root  /api;       index  index.html index.htm;    }

等于:

    # 附件    location /attachment/ {       alias  /api/attachment/;       index  index.html index.htm;    }