Skip to content

Instantly share code, notes, and snippets.

@codenoid
Created November 20, 2021 13:49
Show Gist options
  • Save codenoid/9270499510a4035131b22cbeca056374 to your computer and use it in GitHub Desktop.
Save codenoid/9270499510a4035131b22cbeca056374 to your computer and use it in GitHub Desktop.
Wordpress + NGINX + Cloudflare SSL + Cloudflare config file
# WORDPRESS + NGINX + CLOUDFLARE SSL
# Make sure you already download cloudflare origin cert and place it wherever you want
# Set Cloudflare SSL Setting to FULL (instead of Flexible)
server {
listen 80;
listen 443;
root /var/www/site.com;
index index.php index.html index.htm;
server_name site.com;
error_log /var/log/nginx/mysite.com_error.log;
access_log /var/log/nginx/mysite.com_access.log;
ssl on;
ssl_certificate /path/to/site/site.pem;
ssl_certificate_key /path/to/site/private.key.pem;
client_max_body_size 100M;
location / {
try_files $uri $uri/ /index.php?$args;
#try_files $uri $uri/ /index.php?q=$uri&$args;
#rewrite ^/(.*)$ /index.php?$1;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
// add this line to your wp-config.php
/* SSL Settings */
define('FORCE_SSL_ADMIN', true);
/* Turn HTTPS ‘on’ if HTTP_X_FORWARDED_PROTO matches ‘https’ */
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
$_SERVER['HTTPS'] = 'on';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment