URLs not correctly rewritten - mod proxy error - php

I am running the official docker php image: php:7.4-apache
Some URLs are not correctly being rewritten. We are seeing IPs in some links in the docker container but not when we test locally in MAMP.
These are the types of rewrites we are doing in the htaccess file :
RewriteRule ^gift-cards/(.*)$ http://34.245.51.253/gift-cards/$1 [P]
### Redirect for merchants pages
RewriteRule ^merchants/(.*)$ http://34.245.51.253/merchants/$1 [P]
The logs are showing:
[Mon Nov 14 12:00:14.313116 2022] [proxy:debug] [pid 26] mod_proxy.c(1503): [client 172.17.0.1:56704] AH01143: Running scheme http handler (attempt 0)
[Mon Nov 14 12:00:14.316758 2022] [proxy_ajp:debug] [pid 26] mod_proxy_ajp.c(769): [client 172.17.0.1:56704] AH00894: declining URL http://34.245.51.253/
I can see a similar question here AH00894: declining URL fcgi
But the container isn't running PHP FPM so I am not sure how to proceed?

Related

Php-generated images intermittently showing after moving to HTTPS

I've switched my website to use https, rather than http, and everything is fine apart from images that are generated as a result of Php code executing (static images are ok). As an example, my phpBB forum is one area where this is happening, where images are sporadically not showing (some are, some aren't, with no common pattern). Even simple Php scripts that generate images are showing this strange behavior. If I go back to HTTP then everything is fine.
The error_log contains the following (just one example of an image failing to render), It's almost as if the file generating the image does not complete its execution.
[Mon Dec 30 12:12:01.347282 2019] [core:error]
[pid 247428:tid 23291082008320] [client 90.248.211.216:0] End of script output before headers: file.php, referer: https://www.ukbutterflies.co.uk/phpBB/viewtopic.php?f=37&t=9757
[Mon Dec 30 12:12:01.347709 2019] [:error]
[pid 235457:tid 23291117729536] [client 90.248.211.216:0] SoftException in Application.cpp:630: Could not execute script "/home4/ukbutte1/public_html/phpBB/download/file.php", referer: https://www.ukbutterflies.co.uk/phpBB/viewtopic.php?f=37&t=9757
[Mon Dec 30 12:12:01.348063 2019] [:error]
[pid 235457:tid 23291117729536] [client 90.248.211.216:0] Caused by SystemException in API_Linux.cpp:458: execve() for program "/opt/cpanel/ea-php71/root/usr/bin/php-cgi" failed: Resource temporarily unavailable, referer: https://www.ukbutterflies.co.uk/phpBB/viewtopic.php?f=37&t=9757
The site .htaccess file includes the following, in case this is relevant (this is intended to direct every access request to a secure URL):
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

Remove server.php using htaccess got error 500

I have a website that can be accessed in two ways:
http://localhost/public/blog
http://localhost/server.php/blog
I use the code below to remove the "public" from the url, and its work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
So I tried to change public/ to server.php/ from above code. But it's does not work.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ server.php/$1 [L]
</IfModule>
Server return error code 500.
The server log log reports:
[Wed Sep 04 01:06:53.801523 2019] [core:error] [pid 546] [client
182.253.16.222:36164] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use
'LimitInternalRecursion' to increase the limit if necessary. Use
'LogLevel debug' to get a backtrace.
So my expectation from the second code is address "http://localhost/server.php/blog" can be access without server.php in there (http://localhost/blog).
Both examples you showed have valid syntax and should work, but you seem to still have problems, which suggests that the two different redirect patterns are interfering with each other somehow, or that you have a circular redirection.
Validating if your configuration works correctly
I've just set up a minimalistic apache project for experimenting with rewrite rules: https://github.com/rpagliuca/apache-rewrite-minimalist-environment
In that project, I tested out a configuration very similar to what you described:
# Apache virtual host config file: vhost.conf
<VirtualHost *:80>
DocumentRoot /var/www/html
RewriteEngine On
LogLevel alert rewrite:trace6
RewriteRule ^(.*)$ /server.php$1 [L]
</VirtualHost>
Also, I've added 2 different PHP files to the project:
# File 1: server.php
Handled by server.php<br/>
URI: <?= $_SERVER['REQUEST_URI'] ?>
The second file is similar:
# File 1: server.php
Handled by index.php<br/>
URI: <?= $_SERVER['REQUEST_URI'] ?>
So I started the project with docker-compose up --build, found out the IP of the container using docker ps and docker inspect, and tested out the following URL: http://192.168.16.2/blog. I got the following output on the browser:
Handled by server.php
URI: /blog
This test shows that this RewriteRule is valid in simple cases (where there is no circular redirection -- for scenarios with circular redirection, please read #Anonymous answer).
If I comment out the line RewriteEngine On line, I get a 404 error on the URL http://192.168.16.2/blog, which supports the conclusion that the redirect rule is indeed working. Also, index.php is only accessible when the RewriteEngine On is commented out. Otherwise, when the redirect engine is enabled, I get the following output:
Handled by server.php
URI: /index.php
The ultimate solution
You might have noticed the line LogLevel alert rewrite:trace6 in the vhost.conf file above.
That line enables debugging for your rewrite rules for Apache 2.4 or later. With that, you can fix your future redirect rules errors with way more ease and speed.
Whenever I run my server with docker-compose up --build, and hit the /blog URI, I get the following output:
app_1_d7cddb74e8bd | [Wed Sep 04 12:27:02.121396 2019] [rewrite:trace2] [pid 17] mod_rewrite.c(483): [client 192.168.16.1:49620] 192.168.16.1 - - [192.168.16.2/sid#7fa770113d98][rid#7fa7737780a0/initial] init rewrite engine with requested uri /blog
app_1_d7cddb74e8bd | [Wed Sep 04 12:27:02.121497 2019] [rewrite:trace3] [pid 17] mod_rewrite.c(483): [client 192.168.16.1:49620] 192.168.16.1 - - [192.168.16.2/sid#7fa770113d98][rid#7fa7737780a0/initial] applying pattern '^(.*)$' to uri '/blog'
app_1_d7cddb74e8bd | [Wed Sep 04 12:27:02.121534 2019] [rewrite:trace2] [pid 17] mod_rewrite.c(483): [client 192.168.16.1:49620] 192.168.16.1 - - [192.168.16.2/sid#7fa770113d98][rid#7fa7737780a0/initial] rewrite '/blog' -> '/server.php/blog'
app_1_d7cddb74e8bd | 192.168.16.2:80 192.168.16.1 - - [04/Sep/2019:12:27:02 +0000] "GET /blog HTTP/1.1" 200 267 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36"
app_1_d7cddb74e8bd | [Wed Sep 04 12:27:02.121550 2019] [rewrite:trace2] [pid 17] mod_rewrite.c(483): [client 192.168.16.1:49620] 192.168.16.1 - - [192.168.16.2/sid#7fa770113d98][rid#7fa7737780a0/initial] local path result: /server.php/blog
app_1_d7cddb74e8bd | [Wed Sep 04 12:27:02.121618 2019] [rewrite:trace2] [pid 17] mod_rewrite.c(483): [client 192.168.16.1:49620] 192.168.16.1 - - [192.168.16.2/sid#7fa770113d98][rid#7fa7737780a0/initial] prefixed with document_root to /var/www/html/server.php/blog
app_1_d7cddb74e8bd | [Wed Sep 04 12:27:02.121630 2019] [rewrite:trace1] [pid 17] mod_rewrite.c(483): [client 192.168.16.1:49620] 192.168.16.1 - - [192.168.16.2/sid#7fa770113d98][rid#7fa7737780a0/initial] go-ahead with /var/www/html/server.php/blog [OK]
app_1_d7cddb74e8bd | [Wed Sep 04 12:27:02.122014 2019] [rewrite:trace2] [pid 17] mod_rewrite.c(483): [client 192.168.16.1:49620] 192.168.16.1 - - [192.168.16.2/sid#7fa770113d98][rid#7fa7736c30a0/subreq] init rewrite engine with requested uri /blog
app_1_d7cddb74e8bd | [Wed Sep 04 12:27:02.122032 2019] [rewrite:trace3] [pid 17] mod_rewrite.c(483): [client 192.168.16.1:49620] 192.168.16.1 - - [192.168.16.2/sid#7fa770113d98][rid#7fa7736c30a0/subreq] applying pattern '^(.*)$' to uri '/blog'
app_1_d7cddb74e8bd | [Wed Sep 04 12:27:02.122048 2019] [rewrite:trace2] [pid 17] mod_rewrite.c(483): [client 192.168.16.1:49620] 192.168.16.1 - - [192.168.16.2/sid#7fa770113d98][rid#7fa7736c30a0/subreq] rewrite '/blog' -> '/server.php/blog'
app_1_d7cddb74e8bd | [Wed Sep 04 12:27:02.122060 2019] [rewrite:trace2] [pid 17] mod_rewrite.c(483): [client 192.168.16.1:49620] 192.168.16.1 - - [192.168.16.2/sid#7fa770113d98][rid#7fa7736c30a0/subreq] local path result: /server.php/blog
app_1_d7cddb74e8bd | [Wed Sep 04 12:27:02.122079 2019] [rewrite:trace2] [pid 17] mod_rewrite.c(483): [client 192.168.16.1:49620] 192.168.16.1 - - [192.168.16.2/sid#7fa770113d98][rid#7fa7736c30a0/subreq] prefixed with document_root to /var/www/html/server.php/blog
app_1_d7cddb74e8bd | [Wed Sep 04 12:27:02.122091 2019] [rewrite:trace1] [pid 17] mod_rewrite.c(483): [client 192.168.16.1:49620] 192.168.16.1 - - [192.168.16.2/sid#7fa770113d98][rid#7fa7736c30a0/subreq] go-ahead with /var/www/html/server.php/blog [OK]
You can follow theses logs, and easily find out where is happening your circular redirection or any other misintended behaviours.
After fixing it, remember to turn off mod_rewrite debugging, especially on production environments.
You’re redirecting every URL, but you should only redirect when server.php is missing.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^server\.php($|/)
RewriteRule ^(.*)$ server.php/$1 [L]
</IfModule>

Cache-miss: htaccess request laravel 5.5

i install laravel 5.5 in my server
it's work well in local host and in one of my servers
when i transfer it to another server it give me error
mydomain.com is currently unable to handle this request.
HTTP ERROR 500
and i get this error on my cpanel error
[Wed Aug 29 13:27:12.060112 2018] [cpanel:warn] [pid 24177:tid 140535283795712] mod_cpanel cpanel_open_htaccess(): Cache-miss: htaccess request for '/home/username/public_html/projectfolder/.htaccess'
[Wed Aug 29 13:27:12.060104 2018] [cpanel:warn] [pid 24177:tid 140535283795712] mod_cpanel cpanel_open_htaccess(): Caching htaccess request for '/home/username/public_html/.htaccess'
[Wed Aug 29 13:27:12.060093 2018] [cpanel:warn] [pid 24177:tid 140535283795712] mod_cpanel cpanel_open_htaccess(): Cache-miss: htaccess request for '/home/username/public_html/.htaccess'
[Wed Aug 29 13:27:12.059812 2018] [cpanel:warn] [pid 24177:tid 140535283795712] mod_cpanel cpanel_open_htaccess(): Cache-miss: htaccess request for '/home/username/.htaccess'

Server truncates/interrupts output when request comes from external computer, but not from 127.0.0.1

Setup:
EasyPHP Dev server 13.1VC11 (Apache 2.2.4, MySQL 5.6.12, PHP 5.5.0)
Windows 7.
Apache is set up with multiple virtual hosts each pointing to a separate folder under ...data\localweb\.
Server also acts as a gateway between internet and local network.
My wife has made a webpage which includes JavaScript and jQuery and PHP.
When I open a browser on my server computer and access the pages, everything works as they should. Via both these addresses:
http://127.0.0.1/liselotte/projekt5/2vs.php
http://liselotte.mine.nu/projekt5/2vs.php
However, when I try to access the page from another computer on my local network, the two longer pages in my wife's project gets truncated. (file 2vs.php, also accessible on the page's main menu as "V/S") It always gets truncated at the same place, in the middle of a 8-letter word, in a piece of HTML formatted text.
I use Firefox and can see when the code cuts off before the browser displays an error message that "transfer was aborted". (It's in Swedish, so I'm a bit uncertain about the exact wording of the message) "The connection to the server was severed during retrieval of the page". (no HTTP-error number)
I have also tried Internet Explorer and Chrome, transfer is cut off at the exact same place every time.
Weirdly enough, the page seems to work when accessed from internet.
The Apache config file contains
Listen 127.0.0.1:80
Listen trilliadin.mine.nu:80 #which is one of the virtual hosts
Listen 192.168.137.1:80 #which is Windows local address assigned to my LAN
I've tested disabling all firewalls, but no difference.
I dumped about 4MB text into a file.html to see if this also gets truncated but the whole text-file gets transferred.
Does anyone recognize these symptoms?
EDIT:
Regarding error-reporting... I do get some weird apache-errors when I start the server.
[Wed Jan 15 21:13:37.989659 2014] [mpm_winnt:notice] [pid 968:tid 424] AH00424: Parent: Received restart signal -- Restarting the server.
Failed loading D:\EasyPHP\binaries\php\php_runningversion\php_xdebug-2.2.2-5.4-vc9.dll
PHP Warning: PHP Startup: in Unknown on line 0
[Wed Jan 15 21:13:39.861663 2014] [mpm_winnt:notice] [pid 968:tid 424] AH00455: Apache/2.4.4 (Win32) PHP/5.5.0 configured -- resuming normal operations
[Wed Jan 15 21:13:39.861663 2014] [mpm_winnt:notice] [pid 968:tid 424] AH00456: Server built: Apr 8 2013 13:46:39
[Wed Jan 15 21:13:39.861663 2014] [core:notice] [pid 968:tid 424] AH00094: Command line: 'D:\\EasyPHP\\binaries\\apache\\bin\\apache.exe -d D:/EasyPHP/binaries/apache'
[Wed Jan 15 21:13:39.861663 2014] [mpm_winnt:notice] [pid 968:tid 424] AH00418: Parent: Created child process 5240
[Wed Jan 15 21:13:40.017663 2014] [mpm_winnt:notice] [pid 5328:tid 436] AH00364: Child: All worker threads have exited.
Failed loading D:\EasyPHP\binaries\php\php_runningversion\php_xdebug-2.2.2-5.4-vc9.dll
PHP Warning: PHP Startup: in Unknown on line 0
[Wed Jan 15 21:13:41.655666 2014] [mpm_winnt:notice] [pid 5240:tid 432] AH00354: Child: Starting 64 worker threads.
But I don't understand what it means. Tonight, the Virtual Host liselotte.mine.nu became unresponsive, while virtual host trilliadin.mine.nu continued working. The problem resolved when I restarted the apache server. (see error log above)

Setting up PHP for Apache on Windows

I have been trying to set up PHP from php.net in my Apache web server (localhost).
Over the last day and a half I've been chasing through documentation at the Apache site, the php.net site, SO, and anywhere else shows a hit for the current error, to try and solve the problems. Here are some details of my current set-up and (possible mis)understanding.
Define SRVROOT "/Apache/00"
ServerRoot "${SRVROOT}"
The public directory of Apache is set to htdocs. Apache is producing listings of the directories under it without any problems through localhost. Just to make bleeding sure that I have the right address and it it is Apache, I do an on/off test as described below.
I ran the Windows MSI supplied for PHP. Then I adjusted the /conf/httpd.conf file to add:
ScriptAlias /php/ "${SRVROOT}/php/"
AddType application/x-httpd-php .php
Note: php, htdocs (public files) & conf directories are all in the root of the same directory, SRVROOT.
Test Apache
http://localhost/lib/
might produce:
Index of /lib
Parent Directory
amd64/
web.jar
x86/
While shutting down Apache and refreshing the listing I see a FF error.
Unable to connect
Firefox can't establish a connection to the server at localhost.
So Apache itself seems to be working fine, when it is running I can do directory listings.
Test PHP
http://localhost/php/
Shows:
Forbidden
You don't have permission to access /php/ on this server.
OK that seems logical, Apache now acknowledges the existence of the directory but says it is not intended to by publicly browsed.
I have an phpinfo.php in the root of the php directory containing.
<?phpinfo();?>
I expect that if I browse to http://localhost/phpinfo.php is should give me information, but instead I get 404 message:
Not Found
The requested URL /phpinfo.php was not found on this server.
For http://localhost/php/phpinfo.php I get forbidden message:
Forbidden
You don't have permission to access /php/phpinfo.php on this server.
Typical error.log
sl:warn] [pid 1504:tid 336] AH01909: RSA certificate configured for localhost:443 does NOT include an ID which matches the server name
[Sun Aug 04 19:06:01.995343 2013] [ssl:warn] [pid 1504:tid 336] AH02292: Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Sun Aug 04 19:06:02.298078 2013] [ssl:warn] [pid 1504:tid 336] AH01909: RSA certificate configured for localhost:443 does NOT include an ID which matches the server name
[Sun Aug 04 19:06:02.298078 2013] [ssl:warn] [pid 1504:tid 336] AH02292: Init: Name-based SSL virtual hosts only work for clients with TLS server name indication support (RFC 4366)
[Sun Aug 04 19:06:02.300031 2013] [mpm_winnt:notice] [pid 1504:tid 336] AH00354: Child: Starting 64 worker threads.
[Sun Aug 04 19:06:03.279523 2013] [authz_core:error] [pid 1504:tid 1004] [client ::1:50589] AH01630: client denied by server configuration: I:/Apache/00/php/index.html
[Sun Aug 04 19:15:39.932843 2013] [authz_core:error] [pid 1504:tid 1004] [client ::1:50599] AH01630: client denied by server configuration: I:/Apache/00/php/
[Sun Aug 04 19:21:49.700421 2013] [authz_core:error] [pid 1504:tid 1004] [client ::1:50608] AH01630: client denied by server configuration: I:/Apache/00/php/phpinfo.php
[Sun Aug 04 19:26:58.432843 2013] [authz_core:error] [pid 1504:tid 1004] [client ::1:50621] AH01630: client denied by server configuration: I:/Apache/00/php/phpinfo.php
[Sun Aug 04 19:37:26.403546 2013] [mpm_winnt:notice] [pid 4400:tid 324] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Sun Aug 04 19:37:28.403546 2013] [mpm_winnt:notice] [pid 1504:tid 336] AH00364: Child: All worker threads have exited.
[Sun Aug 04 19:37:28.418195 2013] [mpm_winnt:notice] [pid 4400:tid 324] AH00430: Parent: Child process 1504 exited successfully.
Question
I want to show the phpinfo.php document. Can anyone see the dumb mistake I am making (I am a newbie at this)?
See also:
These are the primary docs I've been looking at:
http://httpd.apache.org/docs/2.4/
http://www.php.net/docs.php
You're probably getting the permission error because the phpinfo.php file does not have permissions set such that the Apache server you're running can read it. Apache can be configured to drop privileges to a limited user account when it runs, and if your file security permissions for a file don't allow that user account to read the file, you will get permission errors. Remember that this applies to every directory in the final path name, i.e. /Apache and /Apache/00 and /Apache/00/php and /Apache/00/php/phpinfo.php must ALL be readable by the user account that Apache runs under.
Another possibility is that you may need to add a Directory directive in httpd.conf to allow access to /php/ if your httpd.conf has a Directory directive for a default access policy of deny-first.
I also don't see any mention of where you've installed the PHP Apache module DLL into the Apache modules folder, nor where you've added the module in your httpd.conf file. If you don't load the PHP module, PHP files will not pass through PHP.

Categories