NGINX和Angular 2 [英] NGINX and Angular 2
问题描述
我当前的应用程序用户的路由类似于/myapp/,/myapp//,/myaapp/dept/
My current app users routes like this /myapp/, /myapp//, /myaapp/dept/
我的应用当前已通过NGINX部署在内部http服务器中.另一个接受外部流量的服务器也运行NGINX并将其转发到内部服务器.
My app is currently deployed in an internal http server with NGINX. The other server that accepts external traffic, also runs NGINX and forwards it to the internal server.
我已根据文档将baseref =/myapp添加到index.html
I have add baseref=/myapp to the index.html as per documentation
如果用户转到 http://www.myexternalserver.com/myapp ,则该应用程序可以正常工作完美.如果用户在页面内并单击内部链接,例如 http://www.myexternalserver.com/myapp/myparameter ,它可以正常工作.浏览器中的URL更改,页面按预期显示.我猜它是由Angular 2处理的.
If the user goes to http://www.myexternalserver.com/myapp, the app works perfectly. If the user is inside the page and clicks on an internal link like http://www.myexternalserver.com/myapp/myparameter, it works. The url in the browser changes, the page is displayed as intended. I am guessing it's processed by Angular 2.
不幸的是,当用户直接输入URL时: http://www.myexternalserver.com/myapp/myparameter ,我收到NGINX的404错误.
Unfortunately when a user types in the url directly: http://www.myexternalserver.com/myapp/myparameter, I get a 404 error made by NGINX.
我认为我必须配置NGINX设置,但我不知道如何修改NGINX的配置或在网站中可用的内容/默认文件/
I think I have to configure NGINX settings but I don't know how should modify NGINX's config or what to put in the sites-available/default file/
推荐答案
我只是遇到了同样的问题,并找到了解决方案.我的基本href是"/".
I just had this same issue and found a solution. My base href is "/", however.
下面是我的nginx.conf:
Below is my nginx.conf:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name mysite.com www.mysite.com;
root /usr/share/nginx/html;
location / {
try_files $uri$args $uri$args/ /index.html;
}
}
}
这篇关于NGINX和Angular 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!