puma / puma-dev

A tool to manage rack apps in development with puma
BSD 3-Clause "New" or "Revised" License
1.74k stars 105 forks source link

Running puma-dev and apache simultaneously #105

Open dotnofoolin opened 7 years ago

dotnofoolin commented 7 years ago

Not as much as an issue, but more of a "how I fixed it".

I wanted to switch from pow to puma-dev, and followed the README closely. After not getting it to work, and trying a lot of things from issue #66, and seeing similar log entries as #40, I realized that Apache was my problem. I'm on macOS Sierra.

I can't just stop Apache. I need it (for now) for other dev work, namely PHP stuff.

So, I decided to mimic the same setup that pow suggested here: https://github.com/basecamp/pow/wiki/running-pow-with-apache

After doing the standard OS X/macOS puma-dev install, all I did was...

  1. Create a new VirtualHost in /etc/apache/other/zzz_puma-dev.conf. Assumes you have Include /private/etc/apache2/other/*.conf at the bottom of your httpd.conf file. If you have a similar file for pow, you probably should remove it.
<VirtualHost *:80>
  ServerName puma-dev
  ServerAlias *.dev
  ServerAlias *.xip.io

  ProxyPass / http://localhost:9280/
  ProxyPassReverse / http://localhost:9280/
  ProxyPreserveHost On
</VirtualHost>
  1. Edit the ~/Library/LaunchAgents/io.puma.dev.plist file and change the Socket and SocketTLS values from 80/443 to 9280 and 9283.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>Label</key>
   <string>io.puma.dev</string>
   <key>ProgramArguments</key>
   <array>
     <string>/usr/local/Cellar/puma-dev/0.10/bin/puma-dev</string>
     <string>-launchd</string>
     <string>-dir</string>
     <string>~/.puma-dev</string>
     <string>-d</string>
     <string>dev</string>
     <string>-timeout</string>
     <string>15m0s</string>
   </array>
   <key>KeepAlive</key>
   <true/>
   <key>RunAtLoad</key>
   <true/>
   <key>Sockets</key>
   <dict>
       <key>Socket</key>
       <dict>
           <key>SockNodeName</key>
           <string>0.0.0.0</string>
           <key>SockServiceName</key>
           <string>9280</string>
       </dict>
       <key>SocketTLS</key>
       <dict>
           <key>SockNodeName</key>
           <string>0.0.0.0</string>
           <key>SockServiceName</key>
           <string>9283</string>
       </dict>
   </dict>
   <key>StandardOutPath</key>
   <string>/Users/jburks/Library/Logs/puma-dev.log</string>
   <key>StandardErrorPath</key>
   <string>/Users/jburks/Library/Logs/puma-dev.log</string>
</dict>
</plist>
  1. Restart the launchd puma-dev service.
launchctl unload ~/Library/LaunchAgents/io.puma.dev.plist
launchctl load ~/Library/LaunchAgents/io.puma.dev.plist
  1. Restart Apache to pick up the new VirtualHost.
sudo apachectl -k restart

That's all it took for me to get puma-dev and Apache to play nice. I didn't attempt to get HTTPS/SSL working since I don't need it right now.

concept47 commented 7 years ago

You can also change the http port to 81

puma-dev install -http-port 81

so you can access your site on nameofapp.dev:81

That way you don't have to reconfigure apache at all

danderozier commented 5 years ago

Thanks for this, it was a huge help in getting apache and puma-dev to work together.

Getting SSL to work with this setup is pretty easy, here's what I did:

  1. Make sure these modules are uncommented in your httpd.conf:

    LoadModule proxy_module lib/httpd/modules/mod_proxy.so
    LoadModule proxy_http_module lib/httpd/modules/mod_proxy_http.so
    LoadModule ssl_module lib/httpd/modules/mod_ssl.so
  2. Edit the puma-dev virtual host config to listen on port 443, start the SSLProxyEngine, and update the proxy definitions to include https and port 9283.

    <VirtualHost *:443>
    ServerName puma-dev
    ServerAlias *.test
    ServerAlias *.xip.io
    
    SSLProxyEngine on
    
    ProxyPass / https://localhost:9283/
    ProxyPassReverse / https://localhost:9283/
    ProxyPreserveHost On
    </VirtualHost>
bradical commented 4 years ago

Thanks @danderozier. In your example above, what did you do about the certs? Did you create some self-signed certs for your *.test and *.xip.io domains to install in Apache?

bradical commented 4 years ago

Did anyone else get this to work in Apache, and, if so, what did you use for the certificate for puma-dev name and aliases : *.test

danderozier commented 4 years ago

Hey @bradical, sorry for the delay in getting back to you. Yep, I just created some self-signed wildcard certificates, which is a little more involved than a normal cert, but not too bad.

https://medium.com/@pubudu538/how-to-create-a-self-signed-ssl-certificate-for-multiple-domains-25284c91142b

I think I did it just for the .test and .xip.io domains, and didn't worry about puma-dev.

bradical commented 4 years ago

sorry for the delay in getting back to you.

No worries @danderozier! Thanks for responding.

Yep, I just created some self-signed wildcard certificates, which is a little more involved than a normal cert, but not too bad.

Got it. I'll try that. I tried using the certs that puma itself generates but it seems be causing some problems when I use those in Apache. Apache starts ok but the SSL connections through puma-dev virtual hosts seem to grind to a halt after awhile.

bradical commented 4 years ago

Btw, I found this tool: https://github.com/FiloSottile/mkcert be a bit easier and more reliable for generating self-signed certs for anyone on MacOS and using MacPorts or Homebrew: https://donatstudios.com/Local-Certificate-On-macOS-Apache