上手

下载

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;
}

southnan0
156 声望8 粉丝

欲买桂花同载酒,终不似,少年游