关于nginx:nginx-笔记

2次阅读

共计 1169 个字符,预计需要花费 3 分钟才能阅读完成。

上手

下载

http://nginx.org/en/download.html
而后解压到某个门路下

启动

cmd 进入 nginx 目录下
例如我是解压到 E 盘,那么我的 nginx 的路劲是

E:\nginx-1.19.0

window 下启动 nginx

start nginx  

或者双击 nginx.exe
拜访 localhost:80

如果无法访问,查看 80 端口是否被占用

敞开 nginx

nginx 目录下

./nginx.exe -s stop

罕用 api

root

默认依据路是 html 文件夹下
拜访 locahost/a/index.html 时,查找的就是 html 目录下 a /index.html

location /a {
            root   html;
            index  index.html index.htm;~~~~
        }

将根目录批改为 html/helpcenter
拜访 localhost/a/index.html 时,查找的就是 html/helpcenter/a/index.html

location /a {
            root   html/helpcenter/;
            index  index.html index.htm;
        }

alias

同样的配置,拜访 localhost/a/index.html 时,寻找的是 html/helpcenter/index.html

location /a {
            alias   html/helpcenter/;
            index  index.html index.htm;
        }

listen

监听多个端口,对应同样的逻辑

server {
    listen       8000;
    listen       8080;

    location / {
        root   html;
        index  index.html index.htm;
}

监听多个端口,对应不同的逻辑

server {
    listen       8000;

    location / {
        root   html;
        index  index.html index.htm;
}
server {
    listen       8001;

    location / {
        root   html/a/;
        index  index.html index.htm;
}

try_files

语法:

try_files file ... uri;
try_files file ...=code;

例子:

location / {try_files $uri /index.html}

拜访 http://localhost/b
如果不存在 b 的目录, 那么会报404, 在设置了 try_files ,nginx 会先查找b/index.html,发现找不到,那就返回默认的/index.html
uri: 代表的是默认门路

nginx module

ngx_http_index_module

定义作为首选项的文件,file名称能够蕴含变量。依照配置的程序一个个查
语法:

index file ...;

例子:

location / {index index.html index.htm;}

如果没有配置,默认是 index.html

正文完
 0