我在linux aws ec2上运行一个node js服务器。我正在尝试创建一个子域,以便可以在http://api.domain.com
运行节点rest api。
httpd.conf格式
<VirtualHost *:80>
ServerName api.domain.com
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
.htaccess接口
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /server.js
</IfModule>
一切都很好,但当我试着点击时,它就爆炸了。但是
http://api.domain.com/method
(强调double//)工作得很好。如果我刚刚点击http://api.domain//method
就会收到预期的“Cannot get/”错误消息。而且,
http://api.domain/
工作正常我想我需要在我的
http://ip-address:3000/method
文件中有一些额外的条目,但我在那里找不到任何东西。。。 最佳答案
解决方案
我把它用双引号包装代理:
<VirtualHost *:80>
ServerName api.domain.com
ProxyPreserveHost On
# setup the proxy
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass "/" "http://localhost:3000/"
ProxyPassReverse "/" "http://localhost:3000/"
</VirtualHost>
在运行
sudo service httpd restart
之后,一切都按预期工作。