设置默认的nginx位置

时间:2018-10-18 19:39:54

标签: nginx

我正在构建一个在nginx后面的MEAN堆栈应用程序

我的应用程序的角度都是通用的,并且会根据用户访问的URL做出不同的响应,即,如果用户访问my.app/cars,则将转到与访问我的URL不同的网页.app / bicycles

在我的应用程序具有通用性之前,我的nginx开发文件已将所有URL进行了硬编码

server {
    listen 80;
    location /cars {
        ...
    }

    ....
}

但是,既然角度范围是通用的,我希望我的nginx默认将所有请求设置为角度。

我一直在网上闲逛,看来拥有

location / {
    ....
}

应该做到这一点,但是,当我这样做时,出现“无法访问此站点”错误。

关于如何实现默认将nginx设置为angular的任何建议?

我假设人们这样做是因为他们遇到“找不到页面”错误,但是我又找不到任何东西。

谢谢

1 个答案:

答案 0 :(得分:2)

简单:

 if(msg.what == MESSAGE_READ){
                String readMessage = null;
                try {
                    readMessage = new String((byte[]) msg.obj, "ASCII");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                //mReadBuffer.setText(readMessage);
                if (readMessage != null&& !readMessage.isEmpty()) {

                    graficar((Float.parseFloat(readMessage))); // this function set data to linechart

                }
            }

您只需要告诉nginx如果找不到文件该怎么办。
location / { root /your/app/directory; index index.html; try_files $uri $uri/ /index.html; } 将为您解决此问题。

如果您请求try_files

然后它将尝试以下操作:

  1. example.com/foo/bar/123> $uri
  2. /your/app/directory/foo/bar/123> $uri/(来自/your/app/directory/foo/bar/123/index.html指令)
  3. index> /index.html

PS:

如果您指定/your/app/directory/index.html

然后,最后一条规则将考虑index指令。类似于第二个指令。

相关问题