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

How to run node.js app next to Apache on the same domain without using ports

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

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

这样的东西

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

#mainWebsite
<VirtualHost example.com:443>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin webmaster@example.com
  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 webmaster@example.com
    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 :)

下面是我在 Ubuntu 的 Apache 网络服务器中用于子域的配置文件。

<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

等子目录中访问节点应用程序