Saturday, November 17, 2018

Apache Reverse Proxy for Microservice Subdomain

You've got Apache 2 running. What more does a plain-old simple HTML site need, after all?

Now you want to add a microservice, but you don't want to add more hosting. Can you add it to this existing host? Yes you can!

Here's how to add a subdomain - tictactoe.example.com - that will send requests to your microservice that's listening on port 8888.

Put the following in /etc/apache2/sites-available/tictactoe.com.conf

<VirtualHost *:80>
    ServerName tictactoe.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    ProxyPass "/"  "http://example.com:8888/"
    ProxyPassReverse "/"  "http://example.com:8888/"

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


Then add your site:

sudo a2ensite tictactoe.com

The best part is your Go code (or Rust, Ruby, Python, whatever) can just handle HTTP. You can use Let's Encrypt/certbot to add the HTTPS virtual host that will proxy secure traffic to your microservice as well.

Sunday, November 11, 2018

All kinds of Ubuntu troubles (fixed)

All three kinds of Ubuntu troubles (all of them fixed)

1. Can't get Ubuntu to start up without using recovery mode? Try making this change in /etc/defaults/grub

GRUB_CMDLINE_LINUX_DEFAULT="nomodeset" 

But then don't forget to

$ sudo update-grub

I've lost track of all the sites I looked at that steered me in the right direction, but I was still having trouble because I'd forgotten the update-grub step!



2a. Trouble getting VNC to install and start up? Look no further than Ubuntu's own Screen Sharing feature!

2b. Once I got that working, I discovered that I could not connect using:
  • the RealVNC viewer (error: "Unable to connect to VNC Server using your chosen security setting. Either upgrade VNC Server to a more recent version from RealVNC, or select a weaker level of encryption.")
  • MacOS Screen Sharing (error: "The software on the remote computer appears to be incompatible with this version of Screen Sharing.")
Fortunately I found a video explaining the solution. Install and launch dconf Editor. Then navigate to org > gnome > desktop > remote-access and turn off the require-encryption option. Once I did this, I was able to use all of my VNC clients!

Thursday, November 01, 2018

Git won't Pull

Problem: cannot connect to remote

$ git pull
nc: getaddrinfo: nodename nor servname provided, or not known
ssh_exchange_identification: Connection closed by remote host

fatal: Could not read from remote repository.

$ git remote -v
origin git@github.com:blah/blah (fetch)

origin git@github.com:blah/blah (push)

$ cat .git/config
...
sshCommand = ssh -o 'ProxyCommand=nc -X connect -x blah:80 %h %p'
...

Aha!

Possible solution: remove sshCommand line from .git/config unless you are ALWAYS connecting through the proxy server.

Friday, October 26, 2018

Sherry Noodle Soup (v2!)

Back in the day, you could find my recipe for Sherry Noodle Soup on dave-net.com. Well that old domain is long gone. And sadly, I don't think you can even find it on The Wayback Machine!

But I found it on a hard drive and decided to cook up a batch. But nah, that recipe needed a little tweak here and there. So without further ado, here's version two...

Sherry Noodle Soup

Ingredients:
  • A couple chicken bodies or one turkey frame, with a little meat left on (you'll want about two cups of meat off the bones later)
  • 3 quarts, water
  • 1 medium-large onion (half quartered, half chopped)
  • 2 tsp, salt (if you really must)
  • 1 cup, dry sherry
  • 1½ tsp, oregano
  • 1 tsp, thyme
  • 1/8 tsp, ground black pepper
  • 2 cups, chopped carrots
  • 2 cups, chopped celery
  • 1 lb, cooked pasta (or dry + ??? cups, water TBD)

Combine meaty bones, water, half of the onion (quartered) in a large pot. Bring to boil and then simmer for an hour or so.

Remove everything from the broth. Salvage whatever meat you can from the bones. Discard the bones and the soggy onion and the other yucky stuff. Set aside two cups of meat for later. The rest will make a nice sandwich! you can give to your dog!

Strain the broth. If you like, you can let it cool and skim the fat off the top.

Combine the broth with the meat and the rest of the raw onion (chopped) and everything else except for the pasta, which you should save for later. Bring it all to a boil and then simmer for 30 minutes.

Add the pasta (cooked or dry plus ??? cups of water) and simmer for another ten minutes or so.

Enjoy!!

Saturday, June 16, 2018

Fix your iTunes names (and numbers!)

I made a thing!

https://github.com/dldnh/fix-itunes-names

When Amazon announced they were retiring their Music Storage Subscriptions, I decided to download all of my music.
This was troublesome in a number of ways. The metadata was pretty well screwed up, so there would be songs without an artist name or album name. So I ended up downloading just one album at a time, so I would know which album was which. Yeah, total PITA.
But once that was done, I found I had a number of songs with names like 'dd-tt- Title of the Song' where dd is the disc number and tt is the track number. And thankfully so, since some of these tracks didn't have the disc or track number in the metadata.
So what I've done is made this little AppleScript (called Fix_iTunes_names.scpt) that will go through all of the songs and rename them from 'dd-tt- Title of the Song' to just 'Title of the Song' - but ONLY IF dd matches the disc number and tt matches the track number. So totally safe!
And then I added another Applescript (called Fix_itunes_names_and_numbers.scpt) for more adventurous folks that will also rename songs from 'dd-tt- Title of the Song' to just 'Title of the Song' and ALSO set the disc number and tarck number to dd and tt - but ONLY IF either number was blank to start with.
You don't have to buy me a beer or anything, but if you want to, feel free - and thanks! http://paypal.me/dldnh

Sunday, February 11, 2018

Use curl to test nginx rewrite rules

Be very careful using nginx rewrite. Consider this answer on SO:

The answer author wrote this correct rewrite rule:
location  /foo {
  rewrite /foo/(.*) /$1  break;
  proxy_pass         http://localhost:3200;
  proxy_redirect     off;
  proxy_set_header   Host $host;
}
Which was later edited erroneously:
location  /foo {
  rewrite /foo(.*) /$1  break;
  proxy_pass         http://localhost:3200;
  proxy_redirect     off;
  proxy_set_header   Host $host;
}
That very subtle change causes nginx to redirect, which is undesirable.

This can easily go unnoticed without curl testing:
$ curl -i http://localhost:8080/foo/bar
HTTP/1.1 301 Moved Permanently
Server: nginx/1.13.8
Date: Sun, 11 Feb 2018 14:18:12 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 40
Connection: keep-alive
Location: /bar

<a href="/bar">Moved Permanently</a>.
I've edited the answer back to the original.

Here's a great article about setting up nginx for serving Go apps.

NOTE: you'll need the GVM readme for an up-to-date command to install GVM.

Friday, December 15, 2017

ISP's and Markets

​The idea that an ISP can collect money from a content provider because a consumer requested content is like saying Safeway should be able to charge Kellog's for the Pop-Tarts I want to eat.

Just wait until Disney starts telling Time Warner to pony up for all the Toy Story they've been carrying. The real problem is that consumers have little or no choice of ISP. Each ISP has a practical monopoly in the markets where they operate.

In order for a free market to be a solution to some problem, there has to be a choice. I may choose from a variety of content providers, but I don't get to choose my cable company.

If a consumer doesn't like the way their ISP is regulating content, they should be able to choose a different ISP. But they can't. Maybe it's time we start regulating ISP's like the monopolies they really are.