nodejs domain without port number

后端 未结 3 1583
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 05:50

I have deployed my nodejs app on a VPS(ubuntu 10.04). I have hosted it on a subdomain (subdomain.myapp.com:3000) and I just have one IP address

By default port 80 is

相关标签:
3条回答
  • 2020-12-13 06:01

    Just an update of @drinchev answer with Apache 2.4.*

    Enable the proxy mode :

    a2ensite proxy_http
    a2ensite proxy
    

    Then :

    <VirtualHost *:80>
        ServerName subdomain.myapp.com
    
        ProxyRequests off
    
        <Proxy *>
                Require all granted
        </Proxy>
    
        ProxyPass / http://localhost:3000/
        ProxyPassReverse / http://localhost:3000/
        ProxyPreserveHost on
    </VirtualHost>
    
    0 讨论(0)
  • 2020-12-13 06:22

    Yes it is possible

    In your apache virtual host file configure with the following

    <VirtualHost *:80>
        ServerName subdomain.myapp.com
    
        ProxyRequests off
    
        <Proxy *>
                Order allow,deny
                Allow from all
        </Proxy>
    
        ProxyPass / http://localhost:3000/
        ProxyPassReverse / http://localhost:3000/
        ProxyPreserveHost on
    </VirtualHost>
    

    You should have

    NameVirtualHost *:80
    

    on top of your file and also Proxy module installed for apache ( I think it is a default configuration for ubuntu )

    LoadModule proxy_module lib/httpd/modules/mod_proxy.so
    

    it must be in your httpd.conf file

    then you should restart apache and it must be fine!

    0 讨论(0)
  • 2020-12-13 06:24

    I needed to do the same thing and @drinchev's answer almost worked for me, but because I run several vhosts on my dev box it didn't quite. A couple minor tweaks kept it from clobbering all my other vhosts.

    <Proxy *>
    

    Needed to be

    <Proxy mynodejs.mydevbox.local>
    

    And

    <VirtualHost *:80>
    

    Needed to be

    <VirtualHost mynodejs.mydevbox.local:80>
    

    So where my local dev machine is named "mydevbox.local" and my node vhost is listening on port 3000, my final config looked more like:

    <VirtualHost mynodejs.mydevbox.local:80>
        DocumentRoot "/Library/WebServer/Documents/mynodejs"
        ServerName mynodejs.mydevbox.local
        ServerAlias mynodejs.mydevbox.local
    
        ProxyRequests off
    
        <Proxy mynodejs.mydevbox.local>
                Order allow,deny
                Allow from all
        </Proxy>
    
        ProxyPass / http://localhost:3000/
        ProxyPassReverse / http://localhost:3000/
        ProxyPreserveHost on
        ErrorLog "/private/var/log/apache2/mynodejs_error_log"
        CustomLog "/private/var/log/apache2/mynodejs_access_log" common
    </VirtualHost>
    
    <VirtualHost myothervhost.mydevbox.local:80>
        DocumentRoot "/Library/WebServer/Documents/myothervhost"
        ServerName myothervhost.mydevbox.local
        ServerAlias myothervhost.mydevbox.local
        ErrorLog "/private/var/log/apache2/myothervhost_error_log"
        CustomLog "/private/var/log/apache2/myothervhost_access_log" common
    </VirtualHost>
    

    Other vhosts could follow

    0 讨论(0)
提交回复
热议问题