Currently we have an Node.JS server with different domainnames. That domainnames are domains from our customers which points to our server with a CNAME and shows their own webshop.
So, let's say our domain is webshop.com and we have 2 customers: customer1.com and customer2.eu. Both domains have a CNAME on # and WWW to webshop.com
Currently we have Apache running with all those domains in a separate config file. The sites are rewriting to localhost:3000/extern/customer-1 where the slug is an unique name based on the shopname. Since we are using RewriteRule the address stays customer1.com, but visitors can see a fast redirect (301).
We are also using Let's Encrypt for https.
This is how a default domain config looks like:
<VirtualHost *:80>
ServerName customer1.com
ServerAlias www.customer1.com
RewriteEngine on
RewriteRule ^(.*)$ https://customer1.com/$1 [R]
</VirtualHost>
<VirtualHost *:443>
ServerName customer1.com
ServerAlias www.customer1.com
RewriteEngine on
RewriteRule ^/$ http://127.0.0.1:8080/extern/customer-1 [P]
RewriteRule ^/([^/]+)$ http://127.0.0.1:8080/extern/customer-1/$1 [P]
RewriteRule ^/(.+) http://127.0.0.1:8080/$1 [P]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/customer1.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/customer1.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/customer1.com/chain.pem
</VirtualHost>
The problem
Currently there is something wrong with Apache/Node.JS so all pages shows an Cannot GET /extern/customer-1 and also on our main domain after a refresh (or redirect).
Is there a way to refactor this whole structure and make a automatized process for adding domains? (We now added all domains manually.) Our frontend app is written in Angular, so maybe there are some solutions?
Related
I have a react js application with connecting API in Laravel. Everything is working fine in localhost. When I'm trying to host this application in my apache server I'm facing a problem.
Trying to achieve the below configuration:
My domain for react application is www.example.com
My domain for Laravel application is www.example.com/api
For this above URL set up
document root folder : /var/www/html
react folder : /var/www/html/react/build
laravel folder : /var/www/html/app/
My virtual host configuration is
<VirtualHost *:443>
# Client React application
DocumentRoot "/var/www/html/react/build"
ServerName example.com
SSLEngine on
# Server Laravel 7 API application
Alias /api /var/www/html/app/public/
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
# Rewrite all requests in /api to server index.php
<Location /api>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ /api/index.php [L]
</Location>
<Directory "/var/www/html/app/public/">
AllowOverride All
Options Indexes FollowSymLinks
</Directory>
</VirtualHost>
<virtualhost *:80>
DocumentRoot /var/www/html
</virtualhost>
Created .htaccess in /var/www/html/.htaccess
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
I'm getting error like 'The requested URL was not found on this server.'
Please help me. what I'm doing wrong in this configuration.
The same configuration is working for angular.
Good evening,
I am trying to set up my apache2 reverse proxy
(following https://github.com/ether/etherpad-lite/wiki/How-to-put-Etherpad-Lite-behind-a-reverse-Proxy)
for etherpad lite
(following https://www.howtoforge.com/tutorial/ubuntu-etherpad-editor-server-installation/, except for the nginx part).
I use http->ssl redirection. Since I use letsencrypt I can only access domain.com and not etherpad.domain.com (at least firefox won't let me and I want to avoid changing that certificate each time I add a new site). So I would like to access my etherpad just as I do access my other sites: domain.com/etherpad. However I always get a 404 trying to get to the site. Looking at a working example, in my nextcloud.conf file I have a line saying:
Alias /nextcloud /local/path/to/nextcloud
However the etherpad reverse proxy virtual host file looks entirely different, the key difference is etherpad not having a local folder but only a mysql database. (Please correct me if this is wrong)
So I tried changing the ssl example from the second link to the following, but it does not work. Please understand that I changed domain name and some internal paths, but "apache2ctl configtest" succeeds and the service is running without error.
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName randomisedDomain.com/etherpad
# SSL configuration
SSLEngine on
# If you hold wildcard certificates for your domain the next two lines are not necessary.
SSLCertificateFile "/working/path/to/fullchain.pem"
SSLCertificateKeyFile "/working/path/to/privkey.pem"
ProxyVia On
ProxyRequests Off
ProxyPreserveHost on
<Location />
AuthType Basic
AuthName "Welcome to the randomisedDomain.com Etherpad"
AuthUserFile /working/path/to/etherpad.passwd
#AuthGroupFile /path/to/svn.group
Require user etherpad
ProxyPass http://localhost:9001/ retry=0 timeout=30
ProxyPassReverse http://localhost:9001/
</Location>
<Location /socket.io>
# This is needed to handle the websocket transport through the proxy, since
# etherpad does not use a specific sub-folder, such as /ws/ to handle this kind of traffic.
# Taken from https://github.com/ether/etherpad-lite/issues/2318#issuecomment-63548542
# Thanks to beaugunderson for the semantics
RewriteEngine On
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:9001/socket.io/$1 [P,L]
ProxyPass http://localhost:9001/socket.io retry=0 timeout=30
ProxyPassReverse http://localhost:9001/socket.io
</Location>
<Proxy *>
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Proxy>
</VirtualHost>
Any help for rerouting the localhost domain to randomisedDomain.com/etherpad is greatly appreciated !
Best regards
MAPster
I need to create a virtual host or domain for my angular 2 application.
In brief, i had followed the below steps:
1) Created virtual host file for my site (From: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts)
2) build the project in prod mode: ng build --prod (got dist folder)
These are my settings files from the above tutorial link that i had made in my server:
etc\apache2\sites-available\mydomain.com.conf
ServerName mydomain.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/Angular2/path_to_my_app
<Directory /var/www/html/Angular2/path_to_my_app>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
In my windows host file added an entry to my site to map the ip
C:\Windows\System32\drivers\etc\hosts
10.*.*.* mydomain.com
In my server etc/host added an entry
etc\hosts
127.0.0.1 mydomain.com
In my angular 2 application's src folder (where index.html resides)
<IfModule mod_rewrite.c>
Options Indexes FollowSymLinks
RewriteEngine On
RewriteBase /var/www/html/Angular2/path_to_my_app
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
And in the same folders index.html:
<base href="/var/www/html/Angular2/path_to_my_app">
My package.json has:
"start": "ng serve --host mydomain.com"
The created domain seems to load (hopefully, assuming deep links works), but when i hit mydomain.com, i get the angular2's folder structure view in my browser, not my site loaded
Where is my configuration incorrect.
Do i need to configure any other file in angular 2. If so which?
ServerName mydomain.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/Angular2/path_to_my_app/src
in etc\apache2\sites-available\mydomain.com.conf, append /src to DocumentRoot
I'm using AngularJS for my Portfolio. I would like to make it compatible and crawled entirely by Googlebot. So, I tried to set the html5 mode in the config.
The '#' is now gone but I can't access to pages directly. Server send me a 404.
I'm using an Apache server. I normally configure my server to route request on index with the .htaccess.
My portfolio is already on a server My portfolio
You can see the code on my github Here
you need to configure your server so that it redirect all routing requests to angular...
read here
How to: Configure your server to work with html5Mode
in apache
<VirtualHost *:80>
ServerName my-app
DocumentRoot /path/to/app
<Directory /path/to/app>
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
</Directory>
</VirtualHost>
I have defined differents hosts in my windows host file, one for every project release (rc1, rc2 etc..)
I would like to create one vhost per release so I can redirect directly to its subdir, for example :
pp15.mv => http://localhost/mv/pp15/.....
pp16.mv => http://localhost/mv/pp16/.....
moreover, I need to redirect the host ppX.mv to an autologin url, something looks like /mv_dbname.php?login=testlogin&mdp=202cb962ac59075b964b07152d234b70
so, finally, I want to type this in my urlbar :
http://pp15.mv
and get redirected to
http://pp15.mv/mv_dbname.php?login=testlogin&mdp=202cb962ac59075b964b07152d234b70
In my virtual host file I have something like this :
<VirtualHost *:80>
ServerName pp15.mv
DocumentRoot "D:\apache\htdocs\mv\pp15"
<Directory "D:\apache\htdocs\mv\pp15">
AllowOverride All
Allow from All
</Directory>
RewriteEngine On
RewriteRule ^/index.php /myvisitv3_dbname.php?login=johsmi&mdp=202cb962ac59075b964b07152d234b70 [R]
RewriteRule ^(/)?$ /myvisitv3_dbname.php?login=johsmi&mdp=202cb962ac59075b964b07152d234b70 [R]
</VirtualHost>
The first redirection works great, but if i try to redirect directly the host, I get a redirection error (too many redirections occured)
Do someone have an idea ?
Thank you previously.
ok, finally here what I did :
<VirtualHost *:80>
ServerName pp16.mv
RewriteEngine on
RewriteCond %{HTTP_HOST} ^pp16\.mv$
RewriteRule ^(/)?$ /mv/pp16/xxx/xxx_dbname.php?login=johsmi&mdp=202cb962ac59075b964b07152d234b70 [R]
</VirtualHost>
no [L] on redirection because app have internal redirection, and no document root because php won't be able to read $_SERVER['REQUESTED_URI'] var correctly, so I could have did this (I prefer)
<VirtualHost *:80>
ServerName pp16.mv
DocumentRoot "D:\apache\htdocs\mv\pp16\xxx"
RewriteEngine on
RewriteCond %{HTTP_HOST} ^pp16\.mv$
RewriteRule ^(/)?$ /xxx_dbname.php?login=johsmi&mdp=202cb962ac59075b964b07152d234b70 [R]
</VirtualHost>
but php would have misread the app path (/ instead of /mv/pp16/xxx/)