PrestaShop - Can't access Admin Panel on nginx - 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.

Related

Wordpress and Laravel working together on NGINX

I'm trying to set up nginx vhost so I can use wordpress and laravel on the same domain.
I put wordpress in the root folder
And in a subfolder /laravel/ installed laravel
Is it possible to make that if for example laravel route /laravel-page in URL, request on server will not go to wordpress /index.php but to Laravel /laravel/public/index.php,
and all other pages are normally requested to /index.php
I would like to whitelist URLs using RegExp, which will be handled by Laravel.
UPDATE:
After a few experiments, I managed to get what I wanted. I added:
location ~ ^/laravel-page(?:/(.*))?$ {
index /laravel/public/index.php;
}
These pages are now handled by Laravel: /laravel-page/1333/. But for some reason, if I enter the address without the slash /laravel-page/1333 , it gives a 404 error, and not from wordpress or laravel, but the usual one from nginx. I tried adding a redirect:
rewrite ^/(.*)/$ /$1 permanent;
It works, but laravel doesn't open.

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.

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.

Imaguard plugin not working with ngnix server

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.

Resources