Skip to content

Instantly share code, notes, and snippets.

@BenFausch
Created March 28, 2018 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenFausch/8d0e9009503f617675dc1ee9679a509c to your computer and use it in GitHub Desktop.
Save BenFausch/8d0e9009503f617675dc1ee9679a509c to your computer and use it in GitHub Desktop.
wordpress local nginx setup with https
#this creates generic ssl certs (will be unsafe, but usuable for local) for any local servers that use ssl_certificate in their nginx conf
#!/bin/bash
echo "Generating an SSL private key to sign your certificate..."
openssl genrsa -des3 -out myssl.key 1024
echo "Generating a Certificate Signing Request..."
openssl req -new -key myssl.key -out myssl.csr
echo "Removing passphrase from key (for nginx)..."
cp myssl.key myssl.key.org
openssl rsa -in myssl.key.org -out myssl.key
rm myssl.key.org
echo "Generating certificate..."
openssl x509 -req -days 365 -in myssl.csr -signkey myssl.key -out myssl.crt
echo "Copying certificate (myssl.crt) to /etc/ssl/certs/"
mkdir -p /etc/ssl/certs
cp myssl.crt /etc/ssl/certs/
echo "Copying key (myssl.key) to /etc/ssl/private/"
mkdir -p /etc/ssl/private
cp myssl.key /etc/ssl/private/
##this file uses a local wp install with childthemes and https on nginx/php-fpm
#goes in sites-available and sites-enabled
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443;
ssl on;
ssl_certificate /etc/ssl/certs/myssl.crt;
ssl_certificate_key /etc/ssl/private/myssl.key;
server_name local-integramed.com *.local-integramed.com;
root /Users/benfausch/sites/integramed-wordpress-multisite;
error_log /usr/local/etc/nginx/logs/phpmyadmin.error.log;
access_log /usr/local/etc/nginx/logs/phpmyadmin.access.log main;
# deny access to hidden files
rewrite /\. /THROW_EXPLICIT_404 break;
# set index priority
index index.php index.html index.htm;
# forward php requests
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# include /usr/local/etc/nginx/conf.d/php-fpm;
# Wordpress /index.php redirect
location / {
try_files $uri $uri/ /index.php?$args;
}
# Use Prod upload folder if local file doesn't exist
location /wp-content/uploads {
try_files $uri $uri/ @produploads;
}
location @produploads {
rewrite (.*) http://prod-integramed.com$1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment