Nginx reverse proxy to Wordpress on an URI
Date : March 29 2020, 07:55 AM
wish of those help I think I managed to come with a so-so solution. Far from being perfect or clean, but... well, it works. blog.domain.com's config: server {
listen 80;
server_name blog.domain.com;
root /home/webserver-blog;
access_log /home/webserver-blog/logs/http_access.log;
error_log /home/webserver-blog/logs/http_error.log;
charset utf-8;
client_max_body_size 65m;
# Some extra speed
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
# Default URLs
location ~* ^/news$ {
rewrite ^ $scheme://domain.com/news/ permanent; # ** HARDCODED production url
break;
}
location / {
try_files $uri $uri/ @redir;
}
location @redir {
rewrite ^/news/(.*)$ /news/index.php?$1 last;
}
# Don't log garbage
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires max;
}
location = /robots.txt {
allow all;
access_log off;
log_not_found off;
}
# Disallow .htaccess or .htpasswd
location ~ /\.ht {
deny all;
}
# Disallow logs
location ~ ^/logs/.*\.(log|txt)$ {
deny all;
}
# Parse PHP
location ~ \.php$ {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
fastcgi_pass php;
}
}
<?php
/*
* domain.com redirector
*/
$production = 'http://domain.com/news/';
// Redirect nicely
if(isset($_SERVER['REQUEST_URI']) and $_SERVER['REQUEST_URI'] !== '/') {
$target = sprintf('%s%s', $production, preg_replace('/^\//', null, $_SERVER['REQUEST_URI']));
header('Location: ' . $target);
}
else header('Location: ' . $production);
<?php
/*
* wordpress loader
*/
$production = 'http://domain.com/news/';
// Allow only reverse-proxied requests
if(!isset($_SERVER['HTTP_X_CUSTOM_SECRET']) or $_SERVER['HTTP_X_CUSTOM_SECRET'] !== md5('your-md5encoded-text-in-proxy_set_header-X-Custom-Secret')) {
die(header('Location: ' . $production));
}
require_once dirname(__FILE__) . '/index-wp-org.php';
|
Reverse proxy to WordPress container
Date : March 29 2020, 07:55 AM
this one helps. The problem is about network configuration I suppose. Your container uses port 80 for wordpress and your host uses the same port for nginx. When you use net: "host"( https://docs.docker.com/engine/reference/run/#/network-settings), your container uses the host's network stack and they conflict trying to bind to the same port. If your mysql server is remotely accessible just remove the net: "host" part and replace the mysql host configuration to how you would connect to it remotely. It should just work.
|
Nginx reverse proxy to Wordpress with Laravel
Date : March 29 2020, 07:55 AM
will be helpful for those in need nginx evaluates location blocks according to various rules as explained by the documentation. To give your location /blog/ a higher precedence than location ~ \.php$, use the ^~ modifier: location ^~ /blog {
proxy_pass http://10.2.7.3;
proxy_set_header Host $host;
}
|
Nginx - Reverse proxy to an already reverse proxied location or double reverse proxy?
Date : March 29 2020, 07:55 AM
To fix this issue The application being loaded is set up to load assets from the server root, not with server root + /node2/
|
Wordpress Rest API reverse Proxy
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , It does not work because /wp-json is not a real file or directory, without reading the .htaccess, local requests will get a 404 not found response, so Apache will continue to forward the request to remote server. To fix this URL rewriting we need to send the requests to the local index.php. ProxyPass /index.php !
ProxyPass /wp-json !
|