[英]How to deploy nodejs, angularjs and apache
I'm working on the seed project now 我现在正在研究种子项目
I want to use 我想用
nodejs
as api server
listening on port 5001
, nodejs
作为api server
侦听端口5001
,
express
as back-end framework, express
为后端框架,
angularjs
as front-end framework, angularjs
作为前端框架,
and apache
as static file server
(such as lots of .js file that angular requires) listening on port 5000
和
apache
作为static file server
(例如很多角度需要的.js文件)监听端口5000
In angular, I have configuration below 在角度,我有下面的配置
app.config(['$locationProvider', function ($locationProvider) {
$locationProvider.html5Mode(true);
$locationProvider.hashPrefix('!');
}]);
As for apache, I add the following configuration to /etc/apache2/sites-available/000-default.conf
至于apache,我将以下配置添加到
/etc/apache2/sites-available/000-default.conf
Listen 5000
<VirtualHost *:5000>
DocumentRoot /var/www/seed/public
<Directory /var/www/seed/public >
AllowOverride All
</Directory>
</VirtualHost>
I also add /public/.htaccess
file 我还添加了
/public/.htaccess
文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# support angular
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /#!/$1
</IfModule>
The current rewrite rule is for angular, because it needs a hashbang when a user refresh the page 当前的重写规则适用于角度,因为当用户刷新页面时它需要一个hashbang
Now I don't know how to redirect api request with URL starting with /api
to port 5001
现在我不知道如何将带有
/api
URL的api请求重定向到端口5001
Is it possible to do this with .htaccess
file? 是否可以使用
.htaccess
文件执行此操作?
And is there any better way to cooperate with nodejs, angularjs and apache? 是否有更好的方式与nodejs,angularjs和apache合作?
I couldn't find any tutorial about this kind of combination... 我找不到关于这种组合的任何教程......
Thanks for reading or answering my question 感谢您阅读或回答我的问题
You need to set up a reverse proxy configuration in Apache. 您需要在Apache中设置反向代理配置。 Ensure firstly that mod_proxy is installed and available.
首先确保mod_proxy已安装且可用。
Then configure your Apache virtual host like this: 然后像这样配置您的Apache虚拟主机:
ProxyRequests Off
<Proxy *>
Order deny, allow
Allow from all
</Proxy>
<Location /api>
ProxyPass http://127.0.0.1:5001
ProxyPassReverse http://1127.0.0.1:5001
</Location>
HTH HTH
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.