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

标签 node.js apache http ubuntu

我正在尝试在我的 ubuntu 服务器上使用带有 apache 的代理,以便在不使用端口的情况下访问我的 node.js 应用程序,但我测试过的解决方案都没有奏效。
基本上我有一个网站在我的域examle.com 上运行,并希望使用myapp.example.com 之类的子域或example.com/myapp 之类的东西访问node.js 应用程序(在端口3000 上运行并使用https)
这是我当前的 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 webs-server 中用于 subdomain 的配置文件。

<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>
您可以访问子域中的 Node 应用程序,例如 https://myapp.example.com
对于托 pipe 目录,您可以尝试以下配置:
<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>
您可以访问子目录中的 Node 应用程序,如 https://example.com/myapp

关于node.js - 如何在不使用端口的情况下在同一域上的 Apache 旁边运行 node.js 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68352368/

相关文章:

node.js - Jasmine 监视没有父对象导出并在 NODE 中使用 ES6 导入的函数

apache - 如何禁用代理内部服务器的重写规则的缓存?

git - 如何通过 HTTP 克隆没有信息/引用的存储库?

android - Android 应用通过 post 发送的参数在 Go 语言编写的后端服务器上始终为空

javascript - 如何在nodejs中将base64视频写入文件

node.js - 从异步事件函数返回对象持久扩展Azure Function Nodejs

node.js - Windows上的全局npm安装位置?

apache - 如何在 Linux 上运行 Tomcat(它在端口 8080 上有 glassfish)

Java速度虚拟机文件#set使用 boolean 变量

Python 请求 head 显示 "301"而 get 返回 "200"