如何在同一域上的 Apache 旁边运行 node.js 应用程序而不使用端口

问题描述 投票:0回答:1

我尝试在我的 ubuntu 服务器上使用带有 apache 的代理,以便在不使用端口的情况下访问我的 node.js 应用程序,但我测试过的解决方案都不起作用。

基本上,我有一个在我的域examle.com上运行的网站,并且想要访问node.js应用程序(在端口3000上运行并使用https),或者使用像myapp.example.com这样的子域,或者使用像example.com/这样的东西我的应用程序

这是我当前的conf文件(不起作用):

#mainWebsite
<VirtualHost example.com:443>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin [email protected]
  ServerName  example.com
  ServerAlias www.example.com
  #Redirect
  #Directory
  <Directory "/var/www/html/example.com">
  Options Indexes FollowSymLinks
  AllowOverride All
  Require all granted
  </Directory>
  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /var/www/html/example.com/public_html
  # Log file locations
  LogLevel warn
  ErrorLog  /var/www/html/example.com/log/error.log
  CustomLog /var/www/html/example.com/log/access.log combined
  # Error Docs
  ErrorDocument 404 /www/html/example.com/errorDocs/404.html
  ErrorDocument 503 /www/html/example.com/errorDocs/503.html
  # SSL
  SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
  Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
#node.js app
<VirtualHost myapp.example.com:433>
    # Admin email, Server Name (domain name), and any aliases
    ServerAdmin [email protected]
    ServerName myapp.example.com
    ServerAlias www.myapp.example.com
    # Proxy
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyVia Full
    <Proxy *>
       Require all granted
    </Proxy>

    <Location /nodejs>
       ProxyPass https://127.0.0.1:3000
       ProxyPassReverse https://127.0.0.1:3000
    </Location>
    # Log file locations
    LogLevel warn
    ErrorLog /var/www/html/example.com/log/error.log
    CustomLog /var/www/html/example.com/acces.log combined
    # Error Docs
    ErrorDocument 404 /www/html/example.com/errorDocs/404.html
    ErrorDocument 503 /www/html/example.com/errorDocs/503.html
    #SSL
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>```

By the way if someone could help me, why my error Docs don't show up, I would be very happy :)
node.js apache http ubuntu
1个回答
7
投票

下面是我在 Ubuntu 中的 Apache webs-server 中用于子域的配置文件。

    <VirtualHost *:443>
      ServerName myapp.example.com

      ProxyRequests Off
      ProxyPreserveHost On
      ProxyVia Full

      <Proxy *>
          Require all granted
      </Proxy>

      ProxyPass / http://127.0.0.1:5000/
      ProxyPassReverse / http://127.0.0.1:5000/

      SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
      SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
      Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost>

您可以在子域中访问节点应用程序,例如https://myapp.example.com

对于子目录托管,您可以尝试以下配置:

    <VirtualHost *:443>
      ServerName example.com

      ProxyRequests Off
      ProxyPreserveHost On
      ProxyVia Full

      <Proxy *>
          Require all granted
      </Proxy>

      ProxyPass /myapp http://127.0.0.1:5000/
      ProxyPassReverse /myapp http://127.0.0.1:5000/

      SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
      SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
      Include /etc/letsencrypt/options-ssl-apache.conf
    </VirtualHost>

您可以在子目录中访问节点应用程序,如https://example.com/myapp

© www.soinside.com 2019 - 2024. All rights reserved.