阅读更多
1 匹配规则
优先级从上到下
location =
:精确匹配
location <absolute path>
:完整路径
location ^~ <path>
:以某个字符串开头,非正则
location ~|~* <regex>
:正则匹配,~
表示大小写敏感,~*
表示大小写不敏感
location <relative path>
:相对路径
location /
:通用匹配
2 配置示例
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| worker_processes 1;
events { worker_connections 1024; }
http { include mime.types; default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server { listen 80; server_name localhost; root /Users/hechenfeng/resources; index index.html;
location / { }
location ~ /api/ { proxy_pass http://localhost:8080; }
location ~ \.html$ { proxy_pass http://localhost:8080; }
}
include servers/*;
|
3 DockerFile
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
| FROM centos:7.5.1804
WORKDIR /
ADD ./nginx-1.8.0.tar.gz /
RUN yum install -y net-tools.x86_64 RUN yum install -y sudo RUN yum install -y vim
# install nginx # 安装后,配置文件位置 /usr/local/nginx/conf # 安装后,nginx二进制文件的位置 /usr/local/nginx/sbin/nginx RUN yum install -y gcc-c++ RUN yum install -y pcre pcre-devel RUN yum install -y zlib zlib-devel RUN yum install -y openssl openssl-devel RUN cd nginx-1.8.0 && ./configure \ --prefix=/usr/local/nginx \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgi && make && make install RUN mkdir -p /var/temp/nginx/client RUN cp /usr/local/nginx/sbin/nginx /usr/local/bin
|
4 文件路径
4.1 Mac
配置文件:/usr/local/etc/nginx/nginx.conf
日志:/usr/local/var/log/nginx
5 参考