Imaguard plugin not working with ngnix server - wordpress

We are using the Imaguard WordPress plugin for some of my websites. One of those websites is on an Nginx server and the plugin doesn't seem to work there. I have followed the instructions mentioned here: https://wordpress.org/support/topic/nginx-4?replies=9 but I'm still unable to get this plugin working.
It seems that those instructions will only work when we are hosting multiple websites on one server. We don't have a vhost.conf so I don't know where to add this code to the Nginx configuration:
if ($http_referer !~* "^http://(.+.)?cupidspulse.com"){
set $rule_0 1$rule_0;
}
if ($rule_0 = "1"){
rewrite ^/(.*).(jpg|png|jpeg|gif)$ /show-image/?img=/$1.$2 redirect;
}
Where should I put this code to get this plugin working?

As stated in the link you gave, you should put this code in your nginx.conf file, if you aren't using multiple .conf files.

Related

How do I configure nginx for WordPress REST API in sub-folder?

I am trying to set up multiple Wordpress sites in sub-folders under our domain (ie not multi-site), but I have difficulty configuring the REST API endpoints. For example, this endpoint works fine:
https://example.com/site1/?rest_route=/wp/v2/posts
But this endpoint gives a 404:
https://example.com/site1/wp-json/wp/v2/posts
I have tried to rewrite the failing url to the working url with these rules in my nginx configuration:
location /site1/wp-json {
rewrite ^/site1/wp-json(.*)$ /site1/?rest_route=$1;
}
location /site1/ {
try_files $uri $uri/ /site1/index.php$is_args$args;
}
I can't see any special handling of wp-json in the WordPress docs or the nginx wiki. What am I missing here? The permalinks for the site is set to Numeric (https://example.com/site1/archives/123) if that might play a role.
Update
Gist of the redacted full config file and the config syntax lints okay:
nginx -c /etc/nginx/nginx.conf -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
I just hit this too, in WP 5.7. Without pretty permalinks, ie with the "Plain" option like ?p=123, my nginx WP installation uses requests like:
/index.php?rest_route=/wp/v2/users/&who=authors...
And these all work fine.
However if I enable pretty permalinks, eg "Post name", /sample-post/, it starts making requests like:
/wp-json/wp/v2/users/?who=authors...
And these all return a 404. For example, editing or publishing posts fails, and browser devtools shows a string of 404s in this format.
But now we know the pattern that works, a solution is clear - we just need to map the not-working format to the working format:
# Resolves WP Gutenberg 404 issue
location /wp-json {
rewrite ^/wp-json(.*)$ /index.php?rest_route=$1 last;
}
I believe that the rewrite directive should be written as shown below:
server {
location /site1/wp-json
{
rewrite ^(/site1/wp-json.*)$ /site1/?rest_route=$1 last;
}
}
I was able to resolve it like this:
location /wordpress/ {
rewrite ^/wordpress/wp-json/(.*?)$ /wordpress/index.php?rest_route=/$1 last;
}
An easy way if your website pages in the subfolder is already working, just add index.php to the url:
https://site1.com/site2/index.php/wp-json/
If your website pages still doesn't work in the subfolder, add this code to nginx/sites-available/website.conf file too:
location /site2 {
rewrite ^(/[^/]+)?(/wp-.*) /site2/$2 break;
rewrite ^/site2/(.*)$ /site2/index.php?q=$1 last;
}

WP migration from apache to nginx results -- 404 -- on https

That was kind of a loaded title.
I moved my site over from Apache to Nginx and I'm learning the hard way that Nginx does things its own ways. It does not like htaccess files, ignores them. This causes problems when running Wordpress, because wordpress supposedly loves to use htaccess files and nginx does not. Why? I have no idea.
Anyways,
I managed to figure out how to bring back the site from the abyss of 404, by placing this code in nginx.conf file
location / {
index index.php index.html;
if (!-e $request_filename)
{
rewrite ^/(.+)$ /index.php last;
}
}
But.
while pages load fine on HTTP, HTTPS still shows dreaded 404. Why? I don't know. So, anybody know what to do next?
Well, it turns out I also have to add the same code on nginx.ssl.conf file.
Why? I don't know, but it works.

PrestaShop - Can't access Admin Panel on nginx

I've tried the same installation of PrestaShop (ver 1.7.5.1) with Apache and nginx (copying the nginx installation into Apache root dir).
When I surf on admin panel I see urls like this:
http://localhost/admin825pqjv9z/index.php/configure/advanced/system-information/?_token=lJz8rH0rLWJJsrgY6tC97KuCrniEs2eps41UEoU5vqY
where index.php is concatenated with the rest of the url
When I use Apache every work fine however with Nginx, I'm getting redirected.
I've tried the following nginx configuration for PrestaShop:
https://gist.github.com/vicobits/86804fa5f6bd9e2a38f353518563590f
but it did not worked.
I just tried the example you provided on my nginx install and it went well.
Did you replace /admin-dev/ by your own admin folder name /admin825pqjv9z/? You should have:
location /admin825pqjv9z/ { # Change this for your admin url
if (!-e $request_filename) {
rewrite ^/.*$ /admin825pqjv9z/index.php last;
}
}
I hope this helps, otherwise I'd be happy to check other options with you.

How do you run multiple instances of expressionengine in subdirectories using nginx?

I'm trying to setup a dev site for a site built in expressionengine. I would have preferred to use a subdomain for my dev site, but I don't control the DNS... So to avoid the hassle I just made a copy in a subdirectory called /~dev/. Like this:
http://example.com/ <-- main site
http://example.com/~dev/ <-- dev site
I copied the database and updated the config files accordingly, and everything works if I pull up either the main site or dev site home pages.... but as soon as I click any link on the dev site, I get a 'Status: 404 Page Not Found' page. I'm thinking that nginx just isn't routing requests correctly. This is my nginx config (in part):
server {
listen 80;
server_name ~^(?<www>.+)\.example\.com$;
root /data/website;
index index.php;
include /etc/nginx/restrictions.conf;
#dev site
location /~dev {
index index.php;
}
I'm not too familiar with nginx (I'm mostly an Apache guy)... so what am I missing here?
Sheesh, I can answer my own question now. Before posting I had spent nearly an hour googling, searching Stack Overflow, and reading nginx docs to no avail... but as soon as I posted my question, I saw this related question pop up in the side bar, which I was able to adapt to my case. facepalm My solution:
location /~dev {
if (!-e $request_filename) {
rewrite ^/~dev/(.*)$ /~dev/index.php/$1 last;
}
}

Preview website doesn't work in virtualmin on nginx

I've just installed virtualmin on nginx (I wanted ISPconfig on nginx, but I didn't succeeded). OS is Centos 6.4.
Since DNS didn't propagate I want to preview a website I've created, through Virtualmin->Services->Preview Website . First it worked, but after I've added the following lines on /etc/nginx/nginx.conf file it didn't worked anymore.
fastcgi_hide_header X-Powered-By;
# enforce NO www
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
# unless the request is for a valid file, send to bootstrap
if (!-e $request_filename)
{
rewrite ^(.+)$ /index.php?q=$1 last;
}
The code above is need for making work permalinks on wordpress website.
What is wrong?
I'm not sure since I am not an expert, but, as per the official documentation,
Nginx does not support CGI, so any applications or Virtualmin scripts that use CGI will not work. Virtualmin should prevent the installation of scripts that require CGI, mod_perl or Apache-specific features.
And when I try to preview a website, it redirects to:
https ://MYHOSTNAME:10000/virtual-server/link.cgi/MYHOSTNAME/http ://website
So it would be actually a broken feature when using nginx in virtualmin, I guess.

Resources