apache 如何在同一个域上运行node.js应用程序,而不使用端口

vs3odd8k  于 2023-11-21  发布在  Apache
关注(0)|答案(1)|浏览(148)

我尝试在我的ubuntu服务器上使用apache代理,以便在不使用端口的情况下访问我的node.js应用程序,但我测试过的解决方案都不起作用。
基本上,我有一个网站在我的域名examle.com上运行,并希望使用myapp.example.com这样的子域或使用example.com/myapp之类的东西来访问node.js应用程序(在端口3000上运行并使用https)
以下是我当前的conf文件(不工作):

  1. #mainWebsite
  2. <VirtualHost example.com:443>
  3. # Admin email, Server Name (domain name), and any aliases
  4. ServerAdmin [email protected]
  5. ServerName example.com
  6. ServerAlias www.example.com
  7. #Redirect
  8. #Directory
  9. <Directory "/var/www/html/example.com">
  10. Options Indexes FollowSymLinks
  11. AllowOverride All
  12. Require all granted
  13. </Directory>
  14. # Index file and Document Root (where the public files are located)
  15. DirectoryIndex index.html index.php
  16. DocumentRoot /var/www/html/example.com/public_html
  17. # Log file locations
  18. LogLevel warn
  19. ErrorLog /var/www/html/example.com/log/error.log
  20. CustomLog /var/www/html/example.com/log/access.log combined
  21. # Error Docs
  22. ErrorDocument 404 /www/html/example.com/errorDocs/404.html
  23. ErrorDocument 503 /www/html/example.com/errorDocs/503.html
  24. # SSL
  25. SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
  26. SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
  27. Include /etc/letsencrypt/options-ssl-apache.conf
  28. </VirtualHost>
  29. #node.js app
  30. <VirtualHost myapp.example.com:433>
  31. # Admin email, Server Name (domain name), and any aliases
  32. ServerAdmin [email protected]
  33. ServerName myapp.example.com
  34. ServerAlias www.myapp.example.com
  35. # Proxy
  36. ProxyRequests Off
  37. ProxyPreserveHost On
  38. ProxyVia Full
  39. <Proxy *>
  40. Require all granted
  41. </Proxy>
  42. <Location /nodejs>
  43. ProxyPass https://127.0.0.1:3000
  44. ProxyPassReverse https://127.0.0.1:3000
  45. </Location>
  46. # Log file locations
  47. LogLevel warn
  48. ErrorLog /var/www/html/example.com/log/error.log
  49. CustomLog /var/www/html/example.com/acces.log combined
  50. # Error Docs
  51. ErrorDocument 404 /www/html/example.com/errorDocs/404.html
  52. ErrorDocument 503 /www/html/example.com/errorDocs/503.html
  53. #SSL
  54. SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
  55. SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
  56. Include /etc/letsencrypt/options-ssl-apache.conf
  57. </VirtualHost>```
  58. By the way if someone could help me, why my error Docs don't show up, I would be very happy :)

字符串

t98cgbkg

t98cgbkg1#

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

  1. <VirtualHost *:443>
  2. ServerName myapp.example.com
  3. ProxyRequests Off
  4. ProxyPreserveHost On
  5. ProxyVia Full
  6. <Proxy *>
  7. Require all granted
  8. </Proxy>
  9. ProxyPass / http://127.0.0.1:5000/
  10. ProxyPassReverse / http://127.0.0.1:5000/
  11. SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
  12. SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
  13. Include /etc/letsencrypt/options-ssl-apache.conf
  14. </VirtualHost>

字符串
您可以在 * https://myapp.example.com * 这样的子域中访问节点应用程序

子目录托管可以尝试以下配置:

  1. <VirtualHost *:443>
  2. ServerName example.com
  3. ProxyRequests Off
  4. ProxyPreserveHost On
  5. ProxyVia Full
  6. <Proxy *>
  7. Require all granted
  8. </Proxy>
  9. ProxyPass /myapp http://127.0.0.1:5000/
  10. ProxyPassReverse /myapp http://127.0.0.1:5000/
  11. SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
  12. SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
  13. Include /etc/letsencrypt/options-ssl-apache.conf
  14. </VirtualHost>


您可以通过类似于***https://example.com/myapp***的方式访问节点应用程序

展开查看全部

相关问题