Created
March 10, 2019 10:28
-
-
Save mshafiee/9fa2f5e997a65a895ad0f9a713fd49f4 to your computer and use it in GitHub Desktop.
Php behind HTTPS/SSL Proxy (nginx, fastcgi)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# nginx server with http + ssl/https (Front) | |
# /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 Php 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 “Php 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment