【问题标题】:How to set nginx location如何设置nginx位置
【发布时间】:2020-02-20 15:23:34
【问题描述】:

这是我的问题

我最近在学习nginx

而且我不知道为什么我可以处理关于位置的配置

这是我的 nginx.conf

server {
    listen       8080;
    server_name  localhost;


    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    root /Users/billyliou/web-site;

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

    location /demo {
        index  index.html index.htm;
        try_files $uri $uri/ /demo/index.html?s=$uri&$args;
    }

    location /test {
        index  index.html index.htm;
        try_files $uri $uri/ /test/index.html?s=$uri&$args;
    }
...

我将两个文件夹放入'/Users/billyliou/web-site'

一个是demo,一个是test。

两者都包含 index.html。

当我输入 localhost:8080 时,它会显示 nginx 默认页面。 当我输入 localhost:8080/demo 时,它会显示演示页面。 但是当我输入 localhost:8080/test 时,它也会显示演示页面。 最后一个出乎我的意料。

如何设置此配置?

【问题讨论】:

    标签: nginx


    【解决方案1】:

    试试这个

    server {
        listen       8080;
        server_name  localhost;
    
        #charset koi8-r;
    
        #access_log  logs/host.access.log  main;
    
        location /demo {
            root    /Users/billyliou/web-site/demo;
            index   index.html index.htm;
            try_files $uri $uri/ /index.html?s=$uri&$args;
        }
    
        location /test {
            root    /Users/billyliou/web-site/test;
            index   index.html index.htm;
            try_files $uri $uri/ /index.html?s=$uri&$args;
        }
    
        location / {
            root    /Users/billyliou/web-site;
            index   index.html;
        }
    
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 2012-11-07
      • 1970-01-01
      • 1970-01-01
      • 2013-04-21
      • 1970-01-01
      • 1970-01-01
      • 2017-06-06
      • 2021-12-07
      • 1970-01-01
      相关资源
      最近更新 更多