Webservice doens't working on fresh install - prestashop

After performing a fresh install of Prestashop ( v 1.6.0.9 ) i've encountered some problems about making the webservice feature avaliable.
I have set the key and i'm able to check the ws's avaliable using the url
http://example.com/webservice/dispatcher.php?ws_key=my_key
And 3 of the relevant result's are:
http://example.com/api/employees?schema=synopsis
http://example.com/api/employees
http://example.com/api/employees?schema=blank
So, testing the links above,i receive the message This page is not available right into my face, i'm not sure why this behaviour.
For aditional information, i followed the steps on the Web Service Tutorial where i downloaded the PSWebServiceLibrary.php file into my root folder, i also created a test file with the content:
<?php
/**
* Created by PhpStorm.
* User: thales.pereira
* Date: 05/01/15
* Time: 16:10
*/
require_once( './PSWebServiceLibrary.php' );
$shop_url="http://localhost";
$secret_key="the_key";
$debug=false;
try {
$webService = new PrestaShopWebservice($shop_url, $secret_key, $debug);
$opt['resource'] = 'customers?schema=synopsis';
$xml = $webService->get($opt);
echo $xml;
}
catch (PrestaShopWebserviceException $ex) {
echo 'Other error: <br />' . $ex->getMessage();
}
But well.. the result was:
Other error:
This call to PrestaShop Web Services failed and returned an HTTP status of 404.
That means: Not Found.
For this dev environment, i'm using MAMP Version 3.0.7.3

The main problem was with nginx regex rules.
Here is what is currently working for me:
server {
listen 80;
server_name 127.0.0.1;
access_log /var/log/nginx/prestashop.access.log;
error_log /var/log/nginx/prestashop.error.log;
root /var/www/prestashop;
if ($http_host != "127.0.0.1") {
rewrite ^ http://127.0.0.1$request_uri permanent;
}
index index.php index.html;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3$4.jpg last;
rewrite ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4$5.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg last;
rewrite ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2$3.jpg last;
rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
rewrite ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$ /js/jquery/plugins/fancybox/images/$1.$2 last;
try_files $uri $uri/ /index.php$is_args$args;
error_page 404 /index.php?controller=404;
location ~* \.(gif)$ {
expires 2592000s;
}
location ~* \.(jpeg|jpg)$ {
expires 2592000s;
}
location ~* \.(png)$ {
expires 2592000s;
}
location ~* \.(css)$ {
expires 604800s;
}
location ~* \.(js|jsonp)$ {
expires 604800s;
}
location ~* \.(js)$ {
expires 604800s;
}
location ~* \.(ico)$ {
expires 31536000s;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
}

Related

Apache to nginx subfolder rewrite for ckeditor

I am using Laravel forge for provisioning webservers and works great right out of the box.
I now encounter the following customer question that I can't seem to manage solve.
In the folder of /file/ckeditor/php/ there is a .htaccess with the following contents.
RewriteCond %{REQUEST_URI} !^/file/ckeditor/php/file(/.*)?$ [NC]
RewriteRule .+ index.php [L]
So basically the request of /file/ckeditor/php/link should rewrite to /file/ckeditor/php/index.php.
The rewrite rule must be skipped when there is no /file/* in the end. I have a current nginx configuration of the following, but maybe I need to set a new document root and a new php handler?
root /home/forge/faked-domain.nl/public;
index index.html index.htm /lib/blue2.php;
location ~* \.(?:jpg|jpeg|webp|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
location / {
try_files $uri $uri/ /lib/blue2.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/faked-domain.nl-error.log error;
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
error_page 404 /lib/blue2.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index /lib/blue2.php;
include fastcgi_params;
}
Hope someone can help me out..

Nginx auth_basic not working for a specific url

I would like to password protect one of the URLs I have and I am trying to do it with:
location /about/payment {
auth_basic "secured site";
auth_basic_user_file /var/www/my.passwd;
}
The problem is that I am asked for the username and paasword. AS soon as I put the right username and password, I am getting a 404 Error with this log:
*55268 open() "/var/www/mysite.com/deployment/web/about/payment" failed (2: No such file or directory), client: 172.16.0.53, server: ~^(?<branch>\w+)\.mysite\.dev$, request: "GET /about/payment HTTP/1.1", host: "deployment.mysite.dev"
EDIT:
The entire nginx conf file is here
server {
listen 80;
access_log ...;
error_log ...;
server_name ~^(?<branch>\w+)\.mysite\.dev$ ~^(?<branch>\w+)\.mysite\.com$;
root /var/www/git/branches/mysite.com/$branch/web;
location /about/payment {
auth_basic "secured site";
auth_basic_user_file /var/www/mysite.passwd;
}
# strip app_eudev.php/ prefix if it is present
rewrite ^/app_eudev\.php/?(.*)$ /$1 permanent;
# remove trailing slash
rewrite ^/(.*)/$ /$1 permanent;
# sitemap rewrite
rewrite ^/sitemap_(.*)$ /sitemap/$1 last;
location / {
try_files $uri #symfonyapp;
}
location #symfonyapp {
rewrite ^(.*)$ /app_eudev.php/$1 last;
}
location /var/www/dms/ {
internal;
alias /var/www/dms/;
}
location #htmlimages {
root /var/www/dms/;
}
location ~ /html/.*\.(png|gif|jpg|pdf)$ {
root ...;
try_files $uri #htmlimages;
}
location /files {
root ...;
}
location /assets {
root ...;
}
location /img {
root ...
}
location ~ \.php(/|$) {
fastcgi_pass 127.0.0.1:9001;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
When nginx find matching location that will process request it ignores any other location that could possibly match request.
In your case before you add auth, request to /about/payment was proceeded by location / which finally passed request to PHP. But as soon as you add location /about/payment request to that URL will be processed by this location which has no special directives so nginx will try to serve static files.
You should add directives that pass request to PHP, in this case it's really simple:
location /about/payment {
auth_basic "secured site";
auth_basic_user_file /var/www/my.passwd;
root ...;
try_files $uri #symfonyapp;
}
E.g. for Wordpress site, I wanna lock the URL
location ~* /block-url/ {
auth_basic "Internal Staging Site";
auth_basic_user_file /etc/nginx/.htpasswd;
try_files $uri $uri/ /index.php?$args; # Most important!
}

CakePHP Htaccess 2 Nginx rewrite

We're moving a CakePHP Framework installation to a server where there's an Nginx running. Previous server had Apache. This CakePHP has multiple sub-installations on subfolders which all include the /app/webroot/ folder. We've managed to get the index.php working but all the other files located under /app/webroot/ like javascript and CSS don't link up there.
Now, we've tried getting this to work on nginx with multiple different variations. The problem is, the site loads up PHP files and clean URL'S work. Loading CSS and JS files which are located under /app/webroot/ don't.
We're trying to set up the root to subdomain.example.com where there's an index.php with a header() function to redirect the user to a folder, where there's CakePHP. Basically multiple sites under sub folders. So the CakePHP sites are http://subdomain.example.com/subfolder
Here's the nginx conf we're trying. I've been trying various different options with no effect.
server {
rewrite ^(.*) http://example.com$1 permanent;
}
server {
listen 80;
server_name example.com www.example.com subdomain.example.com;
access_log /home/example.com/logs/access.log;
error_log /home/example.com/logs/error.log error;
root /home/example.com/public_html/;
index index.php;
gzip_static on;
location /subfolder {
root /home/example.com/public_html/subfolder/;
index index.php;
rewrite ^/subfolder/(/.*)$ /app/webroot$1 break;
try_files $uri $uri/ /subfolder/app/webroot/index.php?$args;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
try_comles $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/example.com-php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
app/webroot/ will be your server root. And separate location for process index.php file.
Example:
server {
listen 80;
server_name yourserver.com;
root /web/path/;
index index.php;
location / {
rewrite ^(/.*)$ /app/webroot$1 break;
try_files $uri $uri/ /app/webroot/index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

How to make Digital Access Pass sub directory (.../dap) to use http onn nginx web server, OS: Ubuntu?

I have nginx web server installed and https domain. I want to make a sub-directory /dap in root folder to use http and exclude from ssl. Please guide me through this.
My /etc/nginx/sites-available virtual host file for this domain is as below,
# WPSINGLE FAST CGI NGINX CONFIGURATION
server {
listen 198.27.70.206:80;
server_name howtofightnow.com;
return 301 https://howtofightnow.com$request_uri;
}
server {
listen 443 ssl;
server_name howtofightnow.com;
ssl on;
ssl_certificate /etc/nginx/ssl/howtofightnow_com.pem;
ssl_certificate_key /etc/nginx/ssl/server.key;
#listen 198.27.70.206:80;
#server_name howtofightnow.com;
access_log /var/log/nginx/howtofightnow.com.access.log rt_cache;
error_log /var/log/nginx/howtofightnow.com.error.log;
root /var/www/howtofightnow.com/htdocs;
index index.php index.htm index.html;
location /zabbix {
if ($scheme ~ ^http:){
rewrite ^(.*)$ https://$host$1 permanent;
}
alias /usr/share/zabbix;
index index.php;
error_page 403 404 502 503 504 /zabbix/index.php;
location ~ \.php$ {
if (!-f $request_filename) { return 404; }
expires epoch;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_pass php;
}
location ~ \.(jpg|jpeg|gif|png|ico)$ {
access_log off;
expires 33d;
}
}
# Use Cached Or Actual File If They Exists, Otherwise Pass Request To WordPress
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
try_files $uri /index.php?args;
include fastcgi_params;
fastcgi_pass php;
}
location /vma {
root /usr/local/vimbadmin/public ;
try_files $uri $uri/ /index.php?$args;
location ~ .php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass php;
}
}
rewrite ^/index.php/register/thanks(.*) /register/thanks$1 permanent;
include /etc/nginx/common/locations.conf;
}
Simply add this location (/dap) to your http server section, plus add a separate root location, as following:
server {
listen 198.27.70.206:80;
server_name howtofightnow.com;
location / {
return 301 https://howtofightnow.com$request_uri;
}
location /dap/ {
# specific rules for this location go here
}
}

Prestashop 1.6 + Nginx + SSL + Multilingual Site - Rewrite Rules

I am struggling with setting up rewrite rules for prestashop with the following setup
Prestashop 1.6
SSL
Multiligual Site (fr + en in my case)
Nginx 1.4.1 (that is important for ssl settings I found)
I have used some of the references below
http://www.prestashop.com/forums/topic/323391-another-nginx-ssl-rewrite-rules-problem/
http://www.prestashop.com/forums/topic/321261-seo-friendly-nginx-rewrites/ (not multilingual)
PRESTASHOP NGINX + REWRITE RULES
and got to this config below.
Everything works except some of my payment modules which return a url like
mysite.com/en/index.php?parameter1=1&parameter2=2
This triggers a 404
It looks like the url should be rewritten as
mysite.com/index.php?parameter1=1&parameter2=2
I have two questions:
Which rule is handling urls like mysite.com/en/16-crews which are working fine?
and what is it translated to ? (I am just curious to understand how that works)
How do I set up a rule to rewrite
mysite.com/en/index.php?parameter1=1&parameter2=2
to
mysite.com/index.php?parameter1=1&parameter2=2
It must also work with the french side of the site /fr/index.php to /index.php
server {
listen 80;
listen 443 ssl;
server_name mysite.com www.mysite.com;
ssl on;
ssl_certificate /etc/nginx/ssl/mysite.crt;
ssl_certificate_key /etc/nginx/ssl/mysite.key;
access_log /var/log/nginx/mysite.access.log;
error_log /var/log/nginx/mysite.error.log;
rewrite_log on;
location / {
root /srv/d_h2osensations/www/www.mysite.com/htdocs;
index index.html index.htm index.php;
rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$1$2.jpg last;
rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$3/$1$2$3$4.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ - img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$ /img/c/$1$2.jpg last;
rewrite ^/c/([a-zA-Z-]+)/[a-zA-Z0-9-]+.jpg$ /img/c/$1.jpg last;
rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$ /img/c/$1$2.jpg last;
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /srv/d_h2osensations/www/www.mysite.com/htdocs$fastcgi_script_name;
}
# Deny access to .htaccess
location ~ /\.ht {
deny all;
}
location /phpmyadmin
{ root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
}
Thanks in advance.
Nic
After a few weeks of looking around this is what works for me
server {
listen 80;
#listen [::]:80 default_server ipv6only=on;
listen 443 default ssl;
#ssl on;
ssl_certificate /etc/nginx/ssl/cert.crt;
ssl_certificate_key /etc/nginx/ssl/cert-key.key;
access_log /var/log/nginx/h2o.prod.access.log;
error_log /var/log/nginx/h2o.prod.error.log;
root /var/www/www.mysite.com/htdocs;
#root /usr/share/nginx/html;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name mysite.com www.mysite.com;
#Specify a charset
charset utf-8;
rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3$4.jpg last;
rewrite ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4$5.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg last;
rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$ /img/c/$1$2.jpg last;
rewrite ^/c/([a-zA-Z-]+)/[a-zA-Z0-9-]+.jpg$ /img/c/$1.jpg last;
rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$ /img/c/$1$2.jpg last;
rewrite ^/order$ /index.php?controller=order last;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php last;
}
# Redirect needed to "hide" index.php
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
location ~ /\.ht {
deny all;
}
}