Vue Router history mode not working under Apache2 - apache

I'm trying to get rid of the reload problem, with routes in history mode. Following the vue docs I created a .htaccess file in the same folder my index.html is located. The path is /var/www/example.com/sever/public. I am not sure if this means it is in subfolder or if subfolder means that the app is under somthing like "example.com/something/index.html", so I tried both of the following configurations.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
and
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /server/public
RewriteRule ^server/public/index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /sever/public/index.html [L]
</IfModule>
I also read that by default .htaccess can be disabled, so I checked the apache2.conf file and found
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
AccessFileName .htaccess
so it seems to be enabled.
example.com.conf looks like this:
<VirtualHost *: 80>
SeverName example.com
ServerAlias www.example.com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
ProxyPass / http://127.0.0.1:8082/
ProxyPassReverse / http://127.0.0.1:8082
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Maybe someone can point out what I'm doing wrong.

Related

Problem with configuring virtual host for single page vuejs app

I want to host a single page Vuejs application that has vue router. I am using apache2 virtual host and I have written the code below for the site.
<VirtualHost *:80>
ServerAdmin example#email.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/dist
<Directory /var/www/example.com/dist/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
</VirtualHost>
The root directory of my project is /var/www/mydomain.com. Now, when I try to install let's encrypt ssl certificate using this command: certbot --apache -d example.com -d www.example.com it gives me an error saying:
Error while running apache2ctl configtest.
Action 'configtest' failed.
The Apache error log may have more information.
AH00526: Syntax error on line 22 of /etc/apache2/sites-enabled/example.com.conf:
RewriteBase: only valid in per-directory config files.
I don't know what to do. Can anyone help me?
I changed my code like below and it worked!
<VirtualHost *:80>
ServerAdmin example#email.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/dist
<Directory /var/www/example.com/dist/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
I put the following code inside the <Directory /var/www/example.com/dist/> </Directory> part and it is working fine.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

Apache configuration for slim3 with ssl

I'm trying to setup my apache configuration file with my slim framework application to use ssl. I've done this in the past but for whatever reason, I'm getting 404 errors when I try to access any page other than the home page. Here is my apache configuration file:
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{SERVER_NAME} =www.my-site.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
ServerAdmin my.email#gmail.com
ServerName www.my-site.com
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /path/to/cert.pem
SSLCertificateKeyFile /path/to/privkey.pem
ServerAdmin my.email#gmail.com
DocumentRoot /wwwroot/sites/my-site/public
ServerName www.my-site.com
ErrorLog logs/www.my-site.com-error_log
CustomLog logs/www.my-site.com-access_log common
<Directory "/wwwroot/sites/my-site/public">
AllowOverride All
RewriteEngine On
RewriteBase /wwwroot/sites/my-site/public
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</Directory>
</VirtualHost>
As stated, my home page works exactly as I'd expect it to work. But when I try to go to https://www.my-site.com/another/page, I get a 404 error.
I have a dev version of this project set up on another server that doesn't use https and I have no problems going to http://dev.my-site.com/another/page.
try set RewriteBase to /
<Directory "/wwwroot/sites/my-site/public">
AllowOverride All
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</Directory>

Vue.js Apache configuration with 301 https redirection (mode history)

I'm using vuejs with mode history enabled, and on the docs I find this Histoy mode docs
but then using Let's Encrypt with certbot I run a command to generate an ssl certificate, but now because of the redirection the following configuration no longer works.
<VirtualHost *:80>
ServerName virtuafest.vir.mx
ServerAdmin webmaster#localhost
DocumentRoot /var/www/virtuafest17/dist
<Directory /var/www/virtuafest17/dist>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =virtuafest.vir.mx
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
How can I solve this without having to create an .htaccess file for the Rewrite conf?
Locate VirtualHost: *:443 in etc/apache2/apache2-le-ssl.conf and add your mod_rewrite there.

HTTPS on laravel5 not fully working

I have been trying to make HTTPS work on Laravel.
The routes do no longer work when the Laravel application goes on HTTPS.
Expected: the route loads the view.
Result: 404 Not found page.
Note: that this does work without https.
Here is my apache2 conf
<VirtualHost *:80>
ServerAdmin email#something
ServerName dev.something
DocumentRoot /var/www/something/development/public_html
DirectoryIndex index.php
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Options -Indexes
<Directory "/var/www/something/development/public_html/">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
AuthUserFile /var/www/something/.htpasswd
AuthName "Password please"
AuthType Basic
Require valid-user
</Directory>
Here is my .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The following code forces laravel5 to go into secure mode.
app/Providers/AppServiceProvider.php
public function boot()
{
\URL::forceSchema('https');
}
Packages like Barryvdh\Debugbar could no longer load their assets.
I honestly no longer have a clue how I could do this.
If you know something about this please respond!

Setting up Symfony2 to work with apache + php-fpm

How does one set up Symfony2 to work on Apache (Apache 2.4) combined with php-fpm?
The aim is to get rid of the .htaccess files and move everything into the apache config.
Without worrying about PHP-FPM, the config looks something like this:
<VirtualHost *:80>
ServerName mysymfonyproject.com
ServerAlias www.mysymfonyproject.com
ErrorLog /path/to/logs/mysymfonyproject_error.log
CustomLog /path/to/logs/mysymfonyproject_access.log combined
DocumentRoot "/path/to/sites/mysymfonyproject/web"
<Directory "/path/to/sites/mysymfonyproject/web">
AllowOverride None
Require all granted
## Start directives copied from standard Sf .htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} .*\.php
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
## End directives copied from standard Sf .htaccess
</Directory>
</VirtualHost>
This thread is for me to post my own findings (and perhaps be corrected if I got it wrong!).
I prefer to just use ProxyPassMatch to make this work. By using this method, your rewrite rules in .htaccess don't need to be changed.
Here is my Apache2 vhost file:
<VirtualHost 192.168.100.51:80>
ServerName grae.labs.brainglove.com
ServerAlias www.grae.labs.brainglove.com
DocumentRoot /srv/symfony2/2.4.4/grae/web
DirectoryIndex app_dev.php
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9001/srv/symfony2/2.4.4/grae/web/$1
<Directory /srv/symfony2/2.4.4/grae/web>
AllowOverride All
Options FollowSymLinks
Require all granted
</Directory>
ErrorLog /var/log/httpd/grae.labs.brainglove.com_error.log
CustomLog /var/log/httpd/grae.labs.brainglove.com_access.log combined
The only line you need to add is the ProxyPassMatch. Everything else stays the same.
Don't forget to change the IP address and path to your symfony2 web directory.
To pass a request through to PHPFPM, the suggested RewriteRule was:
RewriteRule ^(.*\.php(/.*)?)$ fcgi://uds=%2fpath%2fto%2fwww.sock/%{REQUEST_FILENAME} [P,END]
Here's what I ended up. It seems to be working so far, but perhaps there's a better way?
<VirtualHost *:80>
ServerName mysymfonyproject.com
ServerAlias www.mysymfonyproject.com
ErrorLog /path/to/logs/mysymfonyproject_error.log
CustomLog /path/to/logs/mysymfonyproject_access.log combined
DocumentRoot "/path/to/sites/mysymfonyproject/web"
<Directory "/path/to/sites/mysymfonyproject/web">
AllowOverride None
Require all granted
## Start directives copied from standard Sf .htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} .*\.php
# Need to add the phpfpm call here so that php files (including app_dev.php) are passed to FPM
RewriteRule ^(.*\.php(/.*)?)$ fcgi://uds=%2fpath%2to%2fwww.sock/%{REQUEST_FILENAME} [P,END]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
# The main phpfpm call is added at the end to pass php requests through to FPM
RewriteRule ^(.*\.php(/.*)?)$ fcgi://uds=%2fpath%2to%2fwww.sock/%{REQUEST_FILENAME} [P,END]
</IfModule>
## End directives copied from standard Sf .htaccess
</Directory>
</VirtualHost>