I installed prestashop in my localhost. I can login to admin and saw the dashboard. But when I went to other menu, it said 404 not found. The problem was in dashboard, it is using url like index.php?controller , but in other menu it is using admin/index.php. I installed the software under ps directory.
OK - http://localhost/ps/admin/index.php?controller=AdminDashboard&token=3fca2bcd5f31ce3c1cdf951bf5620720#/preview
FAIL - http://localhost/ps/admin/index.php/sell/catalog/products?_token=IIPIHFzRMTdRMvjXGeCiFocCWVXBiwUhWgJIAhgzvtA
Here is my nginx default site configuration inside server {}
location /ps {
root /var/www/;
index index.php;
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?$args;
location ~ /ps/(.+\.php)$ {
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
include snippets/fastcgi-php.conf;
}
}
I am using nginx version 1.18.0 and prestashop version 1.7.8.3 on ubuntu 20.04.4.
My question is, how to fix the nginx setting especially the try_files part so that I can access prestashop's other menu? If that is not possible, how to disable pretty url in prestashop?
Prestashop comes with built-in Apache rewriting rules,
so using a NGINX only enviroment could be troublesome.
You preferably have to switch to Apache as-persystem requirements :
https://devdocs.prestashop.com/1.7/basics/installation/system-requirements/
or consider using Nginx as a reverse proxy for static resources and Apache to serve PHP requests, so native htaccess will work out of the box.
Anyway , have a look at Nginx-specific Prestashop rules:
https://devdocs.prestashop.com/1.7/basics/installation/nginx/
to be integrated in your conf file.
While, in order to completely disable URL rewriting,
you can act on a backoffice setting "URL rewriting" in SEO&URL part, if you are not able to reach that page, you can just adjust "PS_REWRITING_SETTINGS" to 0 in ps_configuration table in your database.
I'm not sure if this will work with the backoffice routes that are now based on Symfony framework, though.
Related
I’m trying to figure out the best way of securing access to my MariaDB database. I have a root non-wordpress site with 2 wordpress sites as directories (/blog and /shop) - each with separate databases - that use phpMyAdmin as a database viewer (accessible at /phpmyadmin). I want to increase the security so that it can’t be hacked so easily. However, I can’t seem to implement any of the recommended security measures.
Creating a .htaccess and in /usr/share/phpmyadmin and adding the following to whitelist IPs and block all other IPs has no effect:
Order Deny,Allow
Deny from All
Allow from 12.34.56.78
Changing the phpMyAdmin url via the config file (so it’s not accessible at /phpmyadmin) also seems to have no effect.
I’m assuming that it’s because apache is not running (I use Nginx to run my main domain and the 2 wordpress sites). I can’t run apache and Nginx simultaneously (presumably because they’re both fighting for port 80), but what I don’t get is that when Nginx is running and apache is supposedly not running, how is the /phpmyadmin link still accessible?
Here’s my .conf file in /etc/nginx/sites-available (also symlinked to sites-enabled):
upstream wp-php-handler-four {
server unix:/var/run/php/php7.4-fpm.sock;
}
server {
listen 1234 default_server;
listen [::]:1234 default_server;
root /var/www/site;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location /blog {
try_files $uri $uri/ /blog/index.php?$args;
}
location /shop {
try_files $uri $uri/ /shop/index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass wp-php-handler-four;
}
}
I followed a tutorial to set this up (maybe I’m misunderstanding how it’s fully set up) but is this not actually using apache to access /phpmyadmin or is it using some web socket? How can I make the above security attempts work?
Note: the /usr/share/phpmyadmin/ dir is symlinked to /var/www/site/
Creating a .htaccess in /usr/share/phpmyadmin and adding the following to whitelist IPs and block all other IPs has no effect:
Order Deny,Allow
Deny from All
Allow from 12.34.56.78
Of course it won't have any effect since this file processed only by apache.
I can’t run apache and Nginx simultaneously (presumably because they’re both fighting for port 80)
In an early days of nginx there was a technique to use nginx for static files and apache to process PHP scripts. Apache was running on some other port (for example, 8080) and listening only on local IP (127.0.0.1). Nginx configuration for that was looking like
upstream apache {
server 127.0.0.1:8080;
}
server {
...
location ~ \.php$ {
proxy_pass http://apache;
}
}
Nowadays it is rarely used since using PHP-FPM is more flexible and gives a less server overhead. However it can be used when you have a complex .htaccess configuration and don't want to rewrite it for nginx/PHP-FPM.
but what I don’t get is that when Nginx is running and apache is supposedly not running, how is the /phpmyadmin link still accessible?
...
Is this not actually using apache to access /phpmyadmin or is it using some web socket?
This configuration uses UNIX socket /var/run/php/php7.4-fpm.sock where PHP-FPM daemon is listening for requests (you can read an introduction to this article to get some additional details).
How can I make the above security attempts work?
One of many possible solutions is
Unlink /usr/share/phpmyadmin/ from /var/www/site/
Use the following location block (put it before the location ~ \.php$ { ... } one:
location ~ ^/phpmyadmin(?<subpath>/.*)? {
allow 12.34.56.78;
# add other IPs here
deny all;
alias /usr/share/phpmyadmin/;
index index.php;
try_files $subpath $subpath/ =404;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$subpath;
fastcgi_pass wp-php-handler-four;
}
}
To add to the otherwise quite thorough answer:
Since Nginx doesn't use .htaccess files or the same syntax as Apache, you aren't being restricted as Apache would do. You may wish to find some other solution, or you could use what's built in to phpMyAdmin: there is a allow/deny functionality built in that you can learn about in the documentation: https://docs.phpmyadmin.net/en/latest/config.html#cfg_Servers_AllowDeny_order (and https://docs.phpmyadmin.net/en/latest/config.html#cfg_Servers_AllowDeny_rules); this will let you restrict access based on username and IP address.
I have Nginx configured and running for some time now. It is handling 3 applications.
Most important is the application #1. It consists of 3 modules: account, participant and admin. Therefore these addresses allow logging into the application for different types of users:
domain.com/account/login, domain.com/participant/login or domain.com/admin/login
Also the homepage domain.com is handled by the same application.
Nginx config was very simple to serve this:
location / {
try_files $uri $uri/ /index.php?$args;
}
root $rootPath;
index index.html index.php;
# PHP
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
try_files $uri /index.php?$args;
}
Thanks to this Home page and Modules were handled by Yii2.
I don't think it should be relevant but there are 2 more apps configured in nginx under locations /application2 and / application3. One is php Zend app and the other - php and javascript app.
Now I need to replace homepage with Wordpress one-pager. Desired solution is to have:
homepage served by Wordpress at domain.com
Yii2 application modules working as before, so that all /participant, /account and /admin locations are served by index.php at $rootPath
2 other applications working as before at domain.com/application2 and domain.com/application3.
For handling Wordpress page I have added one section location = / to redirect main address to Wordpress app. But I cannot add nested location for PHP because I am getting this error: location "/(.+.php$)" cannot be inside the exact location "/"
So I changed the approach. I have set global root to Wordpress path: root $wpPath; and added locations for account, participant and admin modules:
location /account {
root $rootPath;
if (-f $request_filename) {
break;
}
# process PHP here
location ~ /account/(.+\.php$) {
alias $rootPath/$1;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
The main page (Wordpress) works perfectly fine. But the Yii2 application modules (like /aaccount) return 404 - Not found. What is wrong with above setup?
I'm trying to build proper server configuration for nginx serving Yii2 advanced template where backend hosted in a subfolder inside same domain name as frontend.
In this case path_to_yii2 contains whole Yii2 application template and we have these requirements:
path_to_yii2/frontend/web -> should be webroot of / location
path_to_yii2/backend/web -> should be webroot of /backend location
Static content in both folders should be properly served. PHP files should work in both cases.
I wrote and tested such configuration:
server {
listen 80;
server_name localhost;
root <path_to_yii2_application>;
location ~* ^/backend/(.+)$ {
try_files /backend/web/$1 /backend/web/$1/ /backend/index.php?$args;
index /backend/$1/index.php; # not working in case of exact /backend/ request
location ~* ^/backend/(.+\.php)$ {
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/backend/web/$1;
}
}
location / {
try_files /frontend/web/$uri /index.php?$args;
index /$uri/index.php; # not working at all, but / location is served by php even without this line
}
location ~ \.php$ {
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/frontend/web/$fastcgi_script_name;
}
}
And I have some unresolved problems with such configuration. I tested six different options:
FRONTEND:
Static content under / location should be served directly from frontend/web subfolder of yii2 application folder.
Nonexistent content here should be redirected to frontend/web/index.php?$args and served using ~ .php$ location with fastcgi.
Directories under / location should return indexes, if needed served with ~ .php$ location and fastcgi.
BACKEND:
Static content under /backend location should be served directly from backend/web subfolder of yii2 application folder.
Nonexistent content here should be redirected to backend/web/index.php?$argsand served using ~ .php$ location with fastcgi.
Directories under /backend location should return their indexes, if needed served with ~ .php$ location and fastcgi.
I have troubles with directories and their indexes (3 and 6).
First of all, directories for frontend section not working at all, seems that index /$uri/index.php; is wrong for some reason.
Secondly, directories for backend working except exact /backend/ url. Nginx doesn't serve index directive in =/backend/ case.
As a temporarily workaround for backend I added few lines for this exact url:
location = /backend {
return 301 https://$server_name/backend/index.php;
}
location = /backend/ {
return 301 https://$server_name/backend/index.php;
}
How to fix these indexes correctly and what I'm doing wrong?
P.S. There are some similar questions, like Migrating Yii2 from Apache to Nginx - failed on backend app (doesn't provide correct answer, recommends using subdomain) and Nginnx config for Yii 2 Advanced App Template (suggested to move backend content inside yii2 application to frontend folder). I believe that nginx configuration is a proper way of congiguring yii2-application template.
There is also https://github.com/mickgeek/yii2-advanced-one-domain-config repositary which not works in nginx > 1.8.1.
Interesting that apache just needs a symbolic link to make this work. Nginx before 1.8.1 too.
Yii2 application template can be git cloned from here: https://github.com/yiisoft/yii2-app-advanced.git
I would like to know how to rewrite the nginx this url:
Old URL: http://www.webcheats.com.br/vbulletin/showthread.php?t=2175433
New URL: http://www.webcheats.com.br/threads/2175433/
thanks
location = /vbulletin/showthread.php {
return 301 /threads/$arg_t/;
}
If you're using Xenforo 2 on nginx and you had previously migrated from vBulletin there is an addon for Xenforo 2 that handles the redirects:
Xenforo Redirects for vBulletin
But this addon was made for Apache, and out of the box it won't work correctly with the SEO friendly URL feature of Xenforo 2 & nginx. To resolve that issue you need to setup your nginx config to work with SEO friendly URLS using the XF2 Documentation.
Last thing you need to do is read this post which outlines the cause of the issue and the fix. The cause of the problem is this line:
try_files $uri =404;
It stops the redirect from occuring because the old vbulletin php files don't exist. The final fix is to set the block to look like this:
location ~ \.php$ {
try_files $uri /index.php?$uri&$args;
#try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
I have a server with Nginx installed.
I also have 2 domains pointing to that server. (domain1.com and domain2.com). The first domain (domain1.com) is the front website. The other domain (domain2.com) is the CDN for static content like: JS, CSS, images and font files.
I setup domains config files and everything is running fine. The nginx server has PHP running on it.
My question is: How to disable PHP on the second domain (domain2.com) unless the request has "?param=something" in the GET request?!
It will be something like:
// PHP is disabled
if($_GET['param']){
// Enable PHP
}
or should I use:
location ~ /something {
deny all
}
And keep PHP running?!
Note: I need php to process the param i pass to output some JS or CSS.
PHP with nginx is very different than PHP with Apache, since there is no mod_php equiv for nginx (AFAIK).
PHP is handled by totally separate daemon (php-fpm, or by passing the request to an apache server, etc.) As a result, you can bypass php completely simply by letting nginx handle the request without passing it off to php-fpm or apache. There is a good chance that your nginx configuration already is setup only handoff .php files to php-fpm.
Now, if you're trying to have requests such as /some-style.css?foo=bar get handled by php, then I'd suggest simply segregating static resources from dynamic ones.
You could create a third domain, or simply use two separate directories.
/static/foo.css
vs
/dynamic/bar.css?xyz=pdq
You could then handoff to php inside the location blocks.
location ~ /static {
try_files $uri =404;
}
location ~ /dynamic {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
With the above configuration, requests starting with /static will bypass php regardless of file extension (even .php) and requests starting with /dynamic will be passed on the php-fpm regardless of file extension (even .css)