Skip to content

Instantly share code, notes, and snippets.

@dantio
Created May 6, 2017 13:05
Show Gist options
  • Save dantio/95a87823eda19ea9b1e283415dc6bd0d to your computer and use it in GitHub Desktop.
Save dantio/95a87823eda19ea9b1e283415dc6bd0d to your computer and use it in GitHub Desktop.
Wordpress behind HTTPS/SSL Proxy (nginx, fastcgi)
##
# nginx server with http + ssl/https (no WP)
# /etc/nginx/sites-available/example.com
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://no-ssl:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 443 ssl http2;
server_name example.com;
ssl on;
#ssl_certificate /etc/<your_path>/fullchain.pem;
#ssl_certificate_key /etc/<your_path>/privkey.pem;
include snippets/ssl-params.conf;
location / {
proxy_pass http://no-ssl:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
##
# server without ssl/https with fastcgi and WP runnning
# /etc/nginx/sites-available/example-behind-proxy.com
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
set $my_https $https;
if ($http_x_forwarded_proto = 'https') {
set $my_https 'on';
}
fastcgi_param HTTPS $my_https; # set $_SERVER['HTTPS']
fastcgi_param SERVER_NAME $host; # set $_SERVER['SERVER_NAME']
fastcgi_param HTTP_HOST $host; # set $_SERVER['HTTP_HOST']
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
}
# Next: Set the “WordPress Address (URL)” and “Site Address (URL)” to your new HTTPS address.
# See also:
# https://blog.virtualzone.de/2016/08/howto-https-ssl-wordpress-behind-proxy-nginx-haproxy-apache-lighttpd.html
# https://www.variantweb.net/blog/wordpress-behind-an-nginx-ssl-reverse-proxy/
# https://core.trac.wordpress.org/ticket/25239#no0
@dariusz22p
Copy link

thanks for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment