Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a simple way to serve http://localhost as https://someOtherDomain?

I run a local development web server for testing out code changes.

Often I have to test my local changes with remote services that can only connect securely to another domain.

e.g. https://external1.com will only talk to https://someOtherDomain.com, but I've got to test integration of my new code changes with https://external1.com

While I've got a setup configured that works, it seems complex, and took a bit to get setup right. It seems to me that many developers would want to do this same thing, so my question is this:

Is there an easy way to proxy my local webserver as https://someOtherDomain.com ?

EDIT: So maybe this should be asked this way - Does a command line or GUI tool exist that you can pass a local port and a domain name, and it serves your local port securely over https://someOtherDomain.com - no config or SSL cert creation required? Of course it'd be nice if the SSL cert could be replaced through configuration if need be, but by default, it'd work automatically, by using a precanned SSL cert. And even though I'm using Apache, I'm looking for a solution that actually doesnt use Apache - it uses something else. Why? Because I want this solution to work well with any other webserver that's being used by people on our team - as we all run different stacks, and I'd like to be able to let any of us securely serve our sites without having to configure each webserver individually.

Here's my current setup for taking my local webserver and serving it up at https://www.someOtherDomain.com

To test this locally, I've been:

  • editing my hosts file, and adding an entry to make www.someOtherDomain.com point to my local machine, which of course is running my dev server. This makes it so my local site is now available at http://www.someOtherDomain.com

    127.0.0.1 www.someOtherDomain.com

  • Running Apache with a SSL Cert setup and mod_proxy to redirect all https requests to my local http server, thus making my site available at https://www.someOtherDomain.com. Here's my Apache config for this:

    ServerName www.someOtherDomain.com
    
    <Location /balancer-manager>
       SetHandler balancer-manager
    </Location>
    
    ProxyPass /balancer-manager !
    ProxyPass / balancer://mycluster/ 
    
    <Proxy balancer://mycluster>
      BalancerMember http://localhost route=1
    </Proxy>
    ProxyPass / balancer://mycluster
    ProxyPassReverse / balancer://mycluster
    
    SSLHonorCipherOrder On
    SSLProtocol -ALL +SSLv3 +TLSv1
    SSLCipherSuite RC4-SHA:HIGH:!ADH
    
    # Rewrite all http requests to https
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    

I run this on a mac, but am interested in solutions for linux as well. I've seen various Man in the Middle proxy's that sound like they'd work with some configuration... but I'm looking for something really simple to install and run - not just for me, but something I can tell team members about too, as we may all have to do this a lot in the future.

IMPORTANT NOTE: My local webserver isn't running on Port 80, though I've put it this way in the above example, to keep it simple. I understand port 80 on a mac is a bit special, but am very happy with solutions that work fine on all ports but port 80.

like image 704
Brad Parks Avatar asked Aug 20 '14 19:08

Brad Parks


People also ask

Is localhost HTTPS or HTTP?

Browsers treat http://localhost in a special way: although it's HTTP, it mostly behaves like an HTTPS site. On http://localhost , Service Workers, Sensor APIs, Authentication APIs, Payments, and other features that require certain security guarantees are supported and behave exactly like on an HTTPS site.

What is HTTPS local host?

Localhost is the hostname or the computer that is currently in use to run a program, in which the computer has the role as a virtual server. In web development, you can develop a server by editing the code in the localhost and exporting your data to the server.

How do I make HTTPS without SSL certificate?

Just enter the domain name of your website into a browser's address bar, but instead of typing "http://", enter "https://". For example, if your site is normally accessed via "http://www.example.com/", type "https://www.example.com/" instead.


1 Answers

If you want to expose your web on your local machine to the internet try Runscope Passageway, it's easy to setup and "just works" (from experience).

Another alternative is ngrok which I also used, but it didn't always work for me.

like image 87
codeclash Avatar answered Oct 17 '22 07:10

codeclash