【问题标题】:Node.js on Linux endpoint works with 'api//method' but not 'api/method'Linux 端点上的 Node.js 可与“api//method”一起使用,但不能与“api/method”一起使用
【发布时间】:2018-01-14 04:33:38
【问题描述】:

我在 linux aws ec2 上运行节点 js 服务器。我正在尝试创建一个子域,以便可以在 http://api.domain.com 运行我的节点休息 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 时,它会爆炸。但是http://api.domain//method强调双 //) 工作正常。如果我只是点击http://api.domain/,我会收到预期的“无法获取 /”错误消息。

另外,http://ip-address:3000/method 工作正常

我假设我需要在我的 .htaccess 文件中添加一些额外的条目或其他内容,但我在那里找不到任何东西...

【问题讨论】:

    标签: node.js linux apache


    【解决方案1】:

    解决方案

    我通过将代理用双引号括起来使其工作:

    <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 后,一切都按预期运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-20
      • 1970-01-01
      • 2021-08-09
      相关资源
      最近更新 更多