Tag Archives: Nginx

Nginx proxy_redirect

The information you’re about to submit is not secure

Because the site is using a connection that’s not completely secure, your information will be visible to others.

Chrome v86 started warning users about insecure forms. An odd configuration where Nginx was sitting in front of an IIS box was throwing the warning to users, seemingly because IIS wasn’t aware of the SSL layer that Nginx was putting on.

The solution. Adding the following line into the location block in Nginx.

proxy_redirect http://$host/ https://$host/;

No more warnings and now the browser stays inside of https land. Excellent.

By using the $host variable, instead of the actual hostname it allows this to be used inside of a snippet and used across multiple websites without having to change anything.

Sorting 404s in Nginx access Logs

The default Nginx logs can be combined and sorted to gather some useful stats.

  1. Make a working directory and copy current logs over (optional):
    mkdir ~/accesslogs
    sudo cp /var/log/nginx/access.log* ~/accesslogs
    cd ~/accesslogs
  2. Extract logs compressed by log rotate:
    ungzip *.gz
  3. Make a big combined log:
    sudo cat access.log* >> log.combined
  4. Parse the combined log and count the 404’s
    sudo awk '($9 ~ /404/)' log.combined | awk '{print $7}' | sort | uniq -c | sort -rn >> 404sC.txt