When I enable ssl on the website the pages won't load without index.php in the url. I have set Use Web Server Rewrites, Use Secure URLs in Frontend, and Use Secure URLs in Admin to Yes. Offloader header is set to SSL_OFFLOADED. I have cleared the cache on the website and my browser. I have checked phpinfo() and mod_rewrite is enabled. The secure and unsecure url both have https://. I have also replaced the .htaccess file with a fresh copy and it different make any difference.
That is what I have tried from various posts on Stackoverflow and I am unsure what to try next.
Are you using Apache or Nginx? Nginx does not read/use the .htaccess file. You need to use something like this in Nginx config:
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 14d;
log_not_found off;
}
location / {
index index.php;
try_files $uri $uri/ #handler;
}
location #handler {
rewrite / /index.php;
}
location ^~ /app/ { deny all; }
location ^~ /includes/ { deny all; }
location ^~ /lib/ { deny all; }
location ^~ /media/downloadable/ { deny all; }
location ^~ /pkginfo/ { deny all; }
location ^~ /report/config.xml { deny all; }
location ^~ /var/ { deny all; }
location /var/export/ {
auth_basic 'Restricted';
auth_basic_user_file htpasswd;
autoindex on;
}
location /. {
return 404;
}
location ~ .php/ {
rewrite ^(.*.php)/ $1 last;
}
rewrite ^/minify/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
rewrite ^/skin/m/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
location /lib/minify/ {
allow all;
}
Related
I have a setup where a server running nginx will be the front-end and also a load balancer that will upstream to a number of other servers which will be backend.
What I currently have is the webservers running nginx and reverse proxying to apache2 running on port 8000.
The idea is to have visitors first log in to the subdomain apps.xxxx.xxx which contains a list of all the companies applications. Upon clicking on one, then you get redirected to one of the apps which also has it's own login credentials that will be provided to potential customers to have a test run before purchasing.
All these apps are required to run from the one domain but from different paths.
Eg. apps.xxxx.xxx/app1 appps.xxxx.xxx/app2
Find attached my nginx config on the app servers
server {
listen 80 default_server;
root /home/MY_NAME/myapp/public;
index index.html index.htm index.php;
server_name _;
#location / {
# try_files $uri $uri/ /index.php$is_args$args;
#}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
}
location / {
proxy_pass http://SAME_SERVER:8000;
include proxy_params;
#try_files $uri $uri/ /index.php$is_args$args;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
sendfile off;
client_max_body_size 100m;
location ~ /\.ht {
deny all;
}
location ~ /.well-known {
allow all;
}
}
Server Setup:
VPS
Plesk 12.5
Centos 7
NGINX as reverse proxy to Apache 2.4
Path to NGINX config: /etc/nginx/nginx.conf
Plesk provides a GUI Apache & nginx Settings dialog box, but is unable to accept server{} blocks from there.
I've tried the following, and several variations thereof, without success:
server {
server_name xx.xx.xx.xx;
return 301 https://domain.com$request_uri
}
Here's another example of what we are trying to do and need to know where to place the code so NGINX reads and honors the instruction for execution.
server {
server_name newdomain.com www.newdomain.com;
# ngx_pagespeed & ngx_pagespeed handler
#include /usr/local/nginx/conf/pagespeed.conf;
#include /usr/local/nginx/conf/pagespeedhandler.conf;
#include /usr/local/nginx/conf/pagespeedstatslog.conf;
# limit_conn limit_per_ip 16;
# ssi on;
access_log /home/nginx/domains/newdomain.com/log/access.log combined buffer=32k;
error_log /home/nginx/domains/newdomain.com/log/error.log;
root /home/nginx/domains/newdomain.com/public;
location / {
# block common exploits, sql injections etc
#include /usr/local/nginx/conf/block.conf;
# Enables directory listings when index file not found
#autoindex on;
}
location /forums {
try_files $uri $uri/ /index.php;
}
location ~^(/forums/page/).*(\.php)$ {
try_files $uri $uri/ /index.php;
}
# Mask fake admin directory
location ~^/forums/admin/(.*)$ {
deny all;
}
# Secure real admin directory
location ~^(/forums/mynewadmin/).*(\.php) {
#allow 127.0.0.1;
#deny all;
#auth_basic "Restricted Area";
#auth_basic_user_file $document_root/forums/mynewadmin/.htpasswd;
include /usr/local/nginx/conf/php.conf;
}
# IP.Board PHP/CGI Protection
location ~^(/forums/uploads/).*(\.php)$ {
deny all;
}
location ~^(/forums/hooks/).*(\.php)$ {
deny all;
}
location ~^(/forums/cache/).*(\.php)$ {
deny all;
}
location ~^(/forums/screenshots/).*(\.php)$ {
deny all;
}
location ~^(/forums/downloads/).*(\.php)$ {
deny all;
}
location ~^(/forums/blog/).*(\.php)$ {
deny all;
}
location ~^(/forums/public/style_).*(\.php)$ {
deny all;
}
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
#include /usr/local/nginx/conf/errorpage.conf;
}
Where do I need to place this or similar directing in this scenario to direct all direct IP traffic to the domain name? I've tried placing the snippet in various NGINX config files so far without success.
Thanks.
You can try to add this into Nginx's "additional directives" in UI:
location /forums {
try_files $uri $uri/ /index.php;
}
location ~^(/forums/page/).*(\.php)$ {
try_files $uri $uri/ /index.php;
}
# Mask fake admin directory
location ~^/forums/admin/(.*)$ {
deny all;
}
# IP.Board PHP/CGI Protection
location ~^(/forums/uploads/).*(\.php)$ {
deny all;
}
location ~^(/forums/hooks/).*(\.php)$ {
deny all;
}
location ~^(/forums/cache/).*(\.php)$ {
deny all;
}
location ~^(/forums/screenshots/).*(\.php)$ {
deny all;
}
location ~^(/forums/downloads/).*(\.php)$ {
deny all;
}
location ~^(/forums/blog/).*(\.php)$ {
deny all;
}
location ~^(/forums/public/style_).*(\.php)$ {
deny all;
}
I've ignore all system-wide and commented settings. Also you can try to add content from
include /usr/local/nginx/conf/staticfiles.conf;
include /usr/local/nginx/conf/php.conf;
include /usr/local/nginx/conf/drop.conf;
Pay attention that your web site root is placed into /httpdocs folder, according to this config I've see that you web root was in public directory.
Most easy way is to set default domain for IP xx.xx.xx.xx to domain.com in Tools & Settings > IP addreses > xx.xx.xx.xx
Also you can create .htaccess file in web root of domain.com with content:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xx\.xx\.xx\.xx
RewriteRule (.*) http://domain.com/$1 [R=302,L]
Why it does not work via Additional directives?
plesk include custom directives inside of nginx domain's server{} - so server inside server is not possible. It's by design.
custom directives includinв at the end of nginx domain's server{} so if request was catch by some upper rule or location all other will be ignored for this request.
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!
}
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;
}
}
I have problem with implement my rewrite code from htaccess file into nginx config.
I've already tried generator : http://winginx.com/htaccess for generate my rewrite
code.
My nginx config code:
server {
listen 80;
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
}
server {
listen 80;
root /usr/share/nginx/www;
index index.php;
server_name www.example.com;
error_page 404 http://www.example.com/404.php;
autoindex off;
error_log /usr/share/nginx/www/nginx_error.log warn;
location / {
rewrite ^([^\.]*)$ /$1.php;
}
location = / {
rewrite ^ /index.php;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
I wanna implement this from my .htaccess:
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ admin/index.php?hotelname=$1&do=$2 [QSA]
RewriteRule ^(([A-Za-z0-9-/]+)+)$ admin/index.php?hotelname=$1 [L]
Generated code from tool:
location / {
rewrite ^/([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ /admin/index.php?hotelname=$1&do=$2;
rewrite ^/(([A-Za-z0-9-/]+)+)$ /admin/index.php?hotelname=$1 break;
}
I have alredy tried implement this last lines of code to my location blocks but not working at all..
I will be very greateful for every opinion!
Regards
Makromat
The blind kind of conversion would be
rewrite ^([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)$ admin/index.php?hotelname=$1&do=$2&$query_string last;
rewrite ^(([A-Za-z0-9-/]+)+)$ admin/index.php?hotelname=$1 last;
But I would prefer if I understand the question more to produce a more optimum rewrite.
When do I know if the URL should be passed to /admin or not, give me an actual URI for backend and for frontend.
Usually rewrites are better managed in nginx using nginx way of thinking. And this new way of thinking is more based on try_file.
So you may try something like that (untested):
location ^~ "/([A-Za-z0-9-]+)/([A-Za-z0-9-/_]+)" {
try_files $uri admin/index.php?hotelname=$1&do=$2&$args;
}
location ^~ "(([A-Za-z0-9-/]+)+)" {
try_files $uri /admin/index.php?hotelname=$1;
}
location = / {
rewrite ^ /index.php;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
If direct access on given $urishould never happen, then remove that part from the try_files. Now I'm also unsure of your second regex (([A-Za-z0-9-/]+)+), why not using:
location ^~ "/([A-Za-z0-9-/])+"
Or
location ^~ "/([A-Za-z0-9-])+/"
So there's maybe something I do not see, even in your apache rewrites.