ProxyPassMatch rule for Symfony 2.4 - apache

I am running Apache using mod_proxy_fcgi and PHP-FPM and am trying to get it to work Symfony. This is my first project using Symfony and am just getting a feel for it at the moment..
My vhost definition currently looks like:
<VirtualHost *:80>
ServerName symfony.dev
Documentroot "/vagrant/symfony/web"
DirectoryIndex app.php
ProxyTimeout 600
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:5090/vagrant/symfony/web/$1
<Directory "/vagrant/symfony/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
When I go to http://symfony.dev/app_dev.php/, the page loads, but all the links/paths include the full filesystem page. For example, the link for "Run the demo" is http://symblog.dev/vagrant/symfony/web/app_dev.php/demo/.
Is there a different ProxyPassMatch rule that would work, or a Symfony config that can compensate?
I tried ^/(.*\.php)(/.*)?$ which gets app_dev.php/ to load, but then app_dev.php/demo/ seems to load app_dev.php and not the demo, with broken paths to inline resources.

I had the same problems with ProxyPassMatch, but with and SetHandler everything works fine.
<VirtualHost *:80>
ServerName project.dev
ServerAlias www.project.dev
<FilesMatch \.php$>
SetHandler proxy:fcgi://127.0.0.1:9000
</FilesMatch>
#ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/project/web/$1
## Vhost docroot
DocumentRoot "/var/www/project/web"
## Directories, there should at least be a declaration for /var/www/awesome
<Directory "/var/www/project/web">
AllowOverride All
Order allow,deny
Allow from All
</Directory>
## Load additional static includes
## Logging
ErrorLog "/var/www/project/app/logs/apache2/error.log"
ServerSignature Off
CustomLog "/var/www/project/app/logs/apache2/access.log" combined
## SetEnv/SetEnvIf for environment variables
SetEnv APP_ENV dev
## Custom fragment
</VirtualHost>

Related

Keep original URL after redirection by domain provider

Goal
fharrell.com/* is redirected by the domain provider to hbiostat.org/blog/*. I want to keep the address bar showing fharrell.com/*
Apache2 Setup
/etc/apache2/apache2.conf is standard with the following exception:
<Directory /home/ubuntu/htdocs/>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
/etc/apache2/sites-enabled/hbiostat.org.conf is symbolically linked from /etc/apache2/sites-available/hbiostat.org.conf
hbiostat.org.conf sets the document root as /home/ubuntu/htdocs which has been working well for some time
Contents of hbiostat.org.conf:
<VirtualHost *:443>
ServerAdmin my#email.address
DocumentRoot /home/ubuntu/htdocs
ServerName hbiostat.org
ServerAlias www.hbiostat.org
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/ubuntu/htdocs>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/ubuntu/htdocs/blog>
RewriteEngine on
RewriteBase /
RewriteRule ^hbiostat\.org/blog$ fharrell.com [R]
</Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hbiostat.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hbiostat.org/privkey.pem
</VirtualHost>
<VirtualHost *:80>
ServerName hbiostat.org
ServerAlias www.hbiostat.org
DocumentRoot /home/ubuntu/htdocs
<Directory /home/ubuntu/htdocs/blog>
RewriteEngine on
RewriteBase /
RewriteRule ^hbiostat\.org/blog$ fharrell.com [R]
</Directory>
</VirtualHost>
Systax was checked using sudo apachectl -t.
I checked that mod rewrite is active using sudo a2enmod rewrite and restarted the server with sudo systemctl restart apache2
But this has no effect, with hbiostat.org/blog/* remaining in the addressbar.
Tried:
Many remedies on stackoverflow.com (including the two below) and elsewhere, including putting the commands into an .htaccess file (I'd like to avoid the .htaccess approach).
Any help appreciated.
Redirect domain but keep original url
Redirect subfolder URL but keep original domain name
You can't make the browser display a different domain after a 30x redirect.
mod_rewrite doesn't do what you're thinking it does.

Where does Apache read $domain variable from?

In my operational Wordpress enabled Ubuntu instance, I have a 000-default.conf file with the settings:
./apache2/sites-available/000-default.conf: ServerName $domain
./apache2/sites-available/000-default.conf: ServerAlias www.$domain
grepping for \$domain inside etc gives me basically only this file.
Where does Apache get this value when running my site?
full 000-default.conf:
UseCanonicalName On
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName $domain
ServerAlias www.$domain
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<FilesMatch \.php$>
# 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/var/run/php/php7.4-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
$domain is not a pre-defined variable in Apache HTTPD. The list of variables in the documentation does not have it.
As Environment variables are accessed using a %{VAR}-notation in Apache, so it is not read from the environment either.
It's also not in my 000-default.conf - which means it must be something specific to your setup.
And indeed it is! Wordpress includes that file in sites-available with $domain as a placeholder. During setup, the file gets copied into sites-enabled and the placeholder gets replaced. Look in sites-enabled/000-default.conf and instead of $domain, there should be your domain.

Unable to get Apache docker container to serve virtual host with subdomain

I have a site I currently run that works well, but both to learn and to make it more portable, I've been trying to dockerize it. I'm using the offical apache and php images, and setup my virtual hosts identical to how I have on the running site, just with different domains. Unfortunately, while I can get one to work, the second does not.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName api.gamersplane.local
DocumentRoot /var/www/api
ErrorLog "/var/log/gamersplane.api"
CustomLog "/var/log/gamersplane.api" common
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://api:9000/var/www/$1
ProxyPassReverse ^/(.*\.php(/.*)?)$ fcgi://api:9000/var/www/$1
RewriteEngine On
RewriteBase /
RewriteRule !\.(css|jpg|js|gif|png|ico|eot|woff|ttff|svg|psd)$ dispatch.php
<Directory /var/www/api/>
Options FollowSymLinks
Require all granted
</Directory>
LogLevel notice
</VirtualHost>
<VirtualHost *:80>
ErrorLog "/var/log/gamersplane"
CustomLog "/var/log/gamersplane" common
ProxyPreserveHost On
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://api:9000/var/www/$1
ProxyPassReverse ^/(.*\.php(/.*)?)$ fcgi://api:9000/var/www/$1
ServerName gamersplane.local
ServerAlias *.gamersplane.local
DocumentRoot /var/www
RewriteEngine On
RewriteBase /
RewriteRule !\.(css|jpg|js|gif|png|ico|eot|woff|ttff|svg|psd)$ dispatch.php
<Directory /var/www/>
Options FollowSymLinks
Require all granted
</Directory>
LogLevel notice
</VirtualHost>
Originally, I had the first vhost (api.gamersplane) second, but thought maybe it was the server alias that was the problem. Then I switched positions, and even commented out the base (gamersplane.local), but had no luck. This works on the running site, so I can't figure out what's wrong with it.
Checking the headers returned by Postman, I do see it has the Apache and PHP headers, so it seems to be hitting SOMETHING, I just don't know what.

How to configure different Virtual Hosts based on apache + php_cgi and apache+mod_php?

everybody.
I have a Cent OS 6.6 server with Apache + mod_php site (site1.local). I need to configure second site (site2.local) with php_cgi. So, I created a user, gave him permissions on www-folder, configured site1 as mod_php, created a phpinfo.php. Also, I installed php-cgi,and try to configure virtual hosts, works only first site, on the second site is error:
the requested url /cgi-bin/phpinfo.php was not found onthis server.
That's my configs:
cat /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerAdmin webmaster#site1.local
DocumentRoot /var/www/wwwmaster/site1.local
ServerName site1.local
ServerAlias www.site1.local
ErrorLog logs/site1.local-error_log
CustomLog logs/site1.local-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#site2.local
DocumentRoot /var/www/wwwmaster/site2.local
ServerName site2.local
ServerAlias www.site2.local
ScriptAlias /cgi_bin/ /usr/bin/php-cgi/
Action php-cgi /cgi-bin
AddHandler php-cgi php
<Directory /usr/bin/php-cgi>
Allow from all
</Directory>
<Directory "/var/www/wwwmaster/site2.local/">
<FilesMatch "\.php">
SetHandler php-cgi
</FilesMatch>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order Deny,Allow
Allow from all
</Directory>
ErrorLog logs/site2.local-error_log
CustomLog logs/site2.local-access_log common
</VirtualHost>
What I've done wrong and how can I fix that?
You only have to uncomment the line that says NameVirtualServer *:80 in your apache config file.
If you want virtual server for more than one port, simply put as many NameVirtualServer *:[port number] in the apache config file as you need.

How to serve static files using apache?

I have configured apache 2.2 webserver with tomcat. I want static files of my web application to be served using apache. I made a virtual host entry in httpd.conf
<VirtualHost *:8080>
Alias webcommon_alias C:/webcommon_bk
JkMountFile D:/xampp/apache/conf/myexample.net.properties
ServerName myexample.net
ErrorLog logs/myexample.net-error_log
CustomLog logs/myexample.net-access_log common
<Directory C:/webcommon_bk>
Order allow,deny
Allow from all
RewriteEngine On
RewriteBase /webcommon/
RewriteRule ((.*)\.(js|css|html|gif|png)$) webcommon_alias/$1
</Directory>
</VirtualHost>
But when i fetch this file in browser http://myexample.net:8080/webcommon/img/aboutBox.png i get Object not found! The requested URL was not found on this server.
Try this instead:
<VirtualHost *:8080>
Alias /webcommon C:/webcommon_bk
JkMountFile D:/xampp/apache/conf/myexample.net.properties
ServerName myexample.net
ErrorLog logs/myexample.net-error_log
CustomLog logs/myexample.net-access_log common
<Directory C:/webcommon_bk>
Order allow,deny
Allow from all
RewriteEngine On
RewriteRule ((.*)\.(js|css|html|gif|png)$) /webcommon/$1.$2
</Directory>
</VirtualHost>