skip to Main Content

I’ll start by saying that I’m not an Apache expert nor an Apache beginner to that matter. I have an express server that listens on port 443. I host it on a VPS that’s running Centos7 that hosts about 40 other websites, and as far as I know servers them using Apache (I didn’t really configure it, I used cPanel and WHM).

Now, since I know that Apache is listening to port 443 in order to serve the websites, I wonder how I can combine Apache with my Express server (If there’s a way at all).

I know I could just change the port of my express app, but then the port will show up on the address bar on my application and I don’t want that.

I don’t really know what to try since my knowledge in Apache is limited. I’ll be happy to provide with more details should you’ll need them.

Thanks alot!

EDIT:

I tried editing the default httpd.conf file under /etc/apache2/conf/httpd.conf.

This is what I did:

<VirtualHost MY-IP:443>
ServerName <mydomain.com>
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
 ProxyRequests Off
    <Proxy *>
     Require all granted
    </Proxy>
  ProxyPass / <mydomain:8443.com>
  ProxyPassReverse / <mydomain:8443.com>
  <Location />
       Require all granted
   </Location>
 SSLEngine On
 SSLCertificateFile /var/cpanel/ssl/apache_tls/leadu.co.il/combined
</VirtualHost>

I took the configuration from this post.

With this configuration, when I try and visit the domain I get internal error 500.

2

Answers


  1. In your apache configuration file you should add the following:

    If you want to serve your app from a subfolder (https://yourwebsite/express-app/):

        ProxyPass /express-app/ http://localhost:3000/
        ProxyPassReverse /express-app/ http://localhost:3000/
    

    If you want to serve your app from root (https://yourwebsite):

        ProxyPass / http://localhost:3000/
        ProxyPassReverse / http://localhost:3000/
    

    I assume here your app runs on port 3000. Change it if otherwise.

    Login or Signup to reply.
  2. As you used cPanel to configure Apache, it’s better to add configuration using include files, since cPanel might overwrite /etc/apache2/conf/httpd.conf

    You have to create the file /etc/apache2/conf.d/userdata/ssl/2_4/$user/leadu.co.il/include.conf (replace $user by your cPanel user) with the following content:

    SSLEngine on
    SSLCertificateFile /var/cpanel/ssl/apache_tls/leadu.co.il/combined
    SSLUseStapling off
    SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
    ProxyPass / http://127.0.0.1:3000/
    ProxyPassReverse / http://127.0.0.1:3000/
    

    For more detail, you can check https://ferpython.com/setup-fastapi-in-cpanel

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search