简体   繁体   中英

https for an rails app on not-standard port within the same apache server?

I have an existing apache server with https handling traffic for https://www.example.com .

How can I config rails (and apache) to handle https requests from another port, eg https://www.example.com:6000/api/v1/datafeed/ ?

You can make use of the Apache proxy with balancer module. Here is how I configured rails behind Apache 2.4 with NamedVirtualHost:

Enable the following modules in httpd.conf :

LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so​
LoadModule proxy_http_module modules/mod_proxy_http.so​
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule socache_shmcb_module modules/mod_socache_shmcb.so​

And something like following for your VirtualHost configuration

Listen 127.0.0.1:6000 https

<VirtualHost *:6000>
ServerAdmin webmaster@example.com
ServerName www.example.com

DocumentRoot "rails_root/public"
<Directory "rails_root/public"
    Require all granted
    Options -MultiViews
</Directory>

 ProxyPass / balancer://myapp_cluster/
 ProxyPassReverse / balancer://myapp_cluster/
 ProxyPreserveHost On
 ProxyVia On

 <Proxy balancer://myapp_cluster>
     # Note the port here, this should be the port where your rails app is running.
     BalancerMember http://localhost:3000
 </Proxy>

 SSLEngine on
 SSLProtocol all -SSLv2
 SSLCipherSuite ALL:!ADH!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM
 SSLCertificateFile "/etc/httpd/conf/ssl/certificate_file.crt"
 SSLCertificateKeyFile "/etc/httpd/conf/ssl/certificate_key.key"

 ErrorLog "/var/log/httpd/error.log" 
 CustomLog "/var/log/httpd/access.log" combined
 </VirtualHost>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM