Py学习  »  NGINX

如何使用nginx提供基于URL的角度应用程序?

Nobody • 6 年前 • 1088 次点击  

我想知道如何在使用nginx时提供基于url的角度应用程序。所以假设有一个名为xyz.com/something/的url,每当url中有东西时,我希望ngnix路由到一个角度应用程序。我们是怎么做到的,我在这里看到了类似的问题 like this 但就是不能让它工作。

location /something/ {
    root /var/www/xyz.com/html/something/;
    try_files $uri $uri/ /index.html =404;
    }

假设应用程序通常会响应如下URL:, xyz.com/something/login

但下面的代码运行良好。

location / {
  alias /var/www/xyz.com/html/something/;
  try_files $uri $uri/ /index.html =404;
}

也尝试了一些基本的 described here 却没能成功。

也尝试了第一个答案。

Nginx配置文件:

location /admin {
    root /var/www/xyz.com/html/;
    try_files $uri $uri/ /admin/index.html;
}

location / {
    alias /var/www/xyz.com/html/user/;
    try_files $uri $uri/ /index.html =404;
}

这里/admin&user指的是同一域上存在的两个不同的AngularJs项目。

测试用例:

URL : www.xyz.com/admin/
RESPONSE : Blank page.. 
           accessing index.html but not redirecting properly

URL : www.xyz.com/admin/login
RESPONSE : Blank page..
  ERRORS : Cannot match any routes. URL Segment: 'login'

但我的路线正确。。

有什么建议吗??

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50359
文章 [ 1 ]  |  最新文章 6 年前
Richard Smith
Reply   •   1 楼
Richard Smith    7 年前

“something”太多。文件的路径是通过将URI附加到 root . 见 this document 详细情况。

在您的配置中,文件术语 $uri $uri/ 将不匹配安迪文件。

如果您删除 something 从你的 值,您需要将其添加到 index.html 文件元素。

例如:

location /something/ {
    root /var/www/xyz.com/html;
    try_files $uri $uri/ /something/index.html;
}

就我个人而言,我没有附加 =404 ,但它没有坏处,我知道很多角度的教程似乎认为这是必要的。见 this document 详细情况。