[英]How to configure Nginx to serve both Rails app and Angular on same domain
I'd like to use Nginx to serve both my Rails (using passenger) and an Angular front end. 我想使用Nginx来服务我的Rails(使用乘客)和Angular前端。
Basically, all requests that goes to /
should be directed to Rails and every request that goes to /admin/*
should be redirected to a Angular App. 基本上,所有发送到
/
请求都应定向到Rails,每个发送到/admin/*
请求都应重定向到Angular App。
I've found this question that would theoretically be exactly what I'm looking for. 从理论上讲,我已经找到了这个问题 。 Unfortunately Dmitry's answer is a bit vague for someone (like me) who doesn't know much (next to nothing) about Nginx.
不幸的是,德米特里(Dmitry)的答案对于像我这样对Nginx不太了解(几乎不了解)的人有点含糊。
EDIT: Here's the Nginx configuration that I have tried: 编辑:这是我尝试过的Nginx配置:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 178.62.92.199;
passenger_enabled on;
passenger_app_env development;
root /var/www/netturing/public;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location ~ ^/admin/ {
proxy_pass http: /var/www/client/admin;
}
location / {
proxy_pass http: /var/www/netturing/public;
}
}
Could someone extend the answer a bit? 有人可以扩大答案吗?
Thanks! 谢谢!
I think haproxy it's a better tool to do this. 我认为haproxy是执行此操作的更好工具。
But I have some rails apps in standalone passenger server with nginx in front. 但是我在独立的乘客服务器中有一些Rails应用,前面有nginx。
My suggested nginx config: 我建议的Nginx配置:
server {
# some config directives
...
# Al turrón !
# Angular App
location ~ ^/admin/ {
proxy_pass http://<URI TO ANGULAR APP>;
}
# Rails App
location / {
proxy_pass http://<URI TO RAILS APP>;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.