How to put wildcard entry into /etc/hosts? - subdomain

I recently wanted to point all subdomains for a test domain, let's say example.com to the localhost. Is there a way to point all requests on *.example.com to resolve to 127.0.0.1

It happens that /etc/hosts file doesn't support wild card entries.
You'll have to use other services like dnsmasq. To enable it in dnsmasq, just edit dnsmasq.conf and add the following line:
address=/example.com/127.0.0.1

use dnsmasq
Assuming that you're using a Debian-based dist(ubuntu, mint..), check if it's installed with
(sudo) systemctl status dnsmasq
If it is just disabled, start it with
(sudo) systemctl start dnsmasq
If you have to install it, write
(sudo) apt-get install dnsmasq
To define domains to resolve edit /etc/dnsmasq.conf like this.
address=/example.com/127.0.0.1
to resolve *.example.com
! You must reload dnsmasq to take effect for the changes !
systemctl reload dnsmasq

Here is the configuration for those trying to accomplish the original goal (wildcards all pointing to same codebase -- install nothing, dev environment ie, XAMPP)
hosts file (add an entry)
file: /etc/hosts (non-windows)
127.0.0.1 example.local
httpd.conf configuration (enable vhosts)
file: /XAMPP/etc/httpd.conf
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
httpd-vhosts.conf configuration
file: XAMPP/etc/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin admin#example.local
DocumentRoot "/path_to_XAMPP/htdocs"
ServerName example.local
ServerAlias *.example.local
# SetEnv APP_ENVIRONMENT development
# ErrorLog "logs/example.local-error_log"
# CustomLog "logs/example.local-access_log" common
</VirtualHost>
restart apache
create pac file:
save as whatever.pac wherever you want to and then load the file in the browser's network>proxy>auto_configuration settings (reload if you alter this)
function FindProxyForURL(url, host) {
if (shExpMatch(host, "*example.local")) {
return "PROXY example.local";
}
return "DIRECT";
}

Related

How to set up Masked Redirect with Google Cloud VM instances

I have a VM with multiple apps. for example:
32.32.32.01/app1
32.32.32.01/app2
32.32.32.01/app3
I have a domain name from namecheap and I want it to use it only for app1.
so www.mydomain.com should take me to 32.32.32.01/app1.
I created URL Redirect Records on namecheap for both aliases (www and #) but it is not working.
Do I have to also do some configuration at the google cloud side?
You need enter via ssh to the VM, you also need a Apache http server, and create a site: ex:
cd /etc/apache2/sites-available
sudo cp 000-default.conf siteName.conf
sudo nano siteName.conf
Add a configuration (i dont remember the exact config, but this can give you a idea of the file content)
<VirtualHost *:80>
ServerAdmin mail#server.co
ServerName domain.co
ServerAlias www.domain.co
DocumentRoot /var/www/site
...
Save the file and restart apache
sudo a2ensite siteName
sudo service apache2 reload

MySQL: "Found option without preceding group in config file"

I have a Windows machine on which I've moved the WAMP www and MySQL data directories to Dropbox.
Those Dropbox folders have downloaded to my Ubuntu laptop.
I'd like to run the websites in /home/me/Dropbox/WAMP/WWW on my Ubuntu laptop using the MySQL data in /home/me/Dropbox/WAMP/SQL/Data.
I've edited /etc/mysql/my.cnf:
datadir=/home/me/Dropbox/WAMP/SQL/Data
I've edited /etc/apache2/sites-available/default.conf:
<VirtualHost *:80>
DocumentRoot "\home\me\Dropbox\WAMP\WWW\site"
ServerName www.site.dev
ServerAlias www.site.dev
<Directory "\home\me\Dropbox\WAMP\WWW\site">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I've edited /etc/hosts:
127.0.0.1 www.site.dev
I've restarted apache2, and when I run www.site.dev in my browser, I am taken to the default apache2 index.html.
When I run >mysql start, I receive:
mysql: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 23!
mysql: [ERROR] Fatal error in defaults handling. Program aborted!
Line 23 of /etc/mysql/my.cnf is:
datadir=/home/me/Dropbox/WAMP/SQL/Data
Help appreciated.
From this answer, I've opened /etc/mysql/my.cnf in Sublime Text editor, and saved it as UT-8 (without BOM), and the issue remains.
Please add [mysqld] at the top of my.cnf and then restart mysql server.
service mysql restart
the file my.cnf should be saved as ANSI encode,and [mysqld] group at the start of the file.

Apache2 webserver ubuntu 16.04 not allowing any page besides index.html

I'm attempting to add multiple html pages to my website.
I've pasted the files into /var/www/html which is what my virtual hosts file is pointing to. However, whenever I try to navigate to another html page such as domain.com/page.html it fails to find anything.
I feel like I'm missing a setting or something with apache2 that is preventing me from accessing anything but the index.html. I've checked to insure the files are in the correct directory. I hope someone has some idea whats going on as I'm a bit lost.
heres the virtual host file;
<VirtualHost 72.222.165.39:7777>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly
ServerName www.birnbaumdesign.com
ServerAlias *.birnbaumdesign.com
ServerAdmin royce.birnbaum#gmail.com
DocumentRoot /var/www/html
<Directory /var/www/html>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

localhost/phpmyadmin giving page not found error

I'm running wampserver.
I had a mysql server crash, and the wampmysqld service would not start up. Also, localhost/phpmyadmin did not show phpmyadmin but gave me a 403 error. I installed the mysql-addon for another mysql version. Then I went to the wampserver icon and did Mysql > Version > and selected the add-on version I'd just downloaded.
This helped, wampmysqld was able to start up, the wampserver icon was able to go green all the way, and my application is working. However, phpmyadmin is giving a 404 error. How do I fix this?
phpmyadmin.conf is:
Alias /phpmyadmin "c:/wamp/apps/phpmyadmin3.3.9/"
# to give access to phpmyadmin from outside
# replace the lines
#
# Order Deny,Allow
# Deny from all
# Allow from 127.0.0.1
#
# by
#
# Order Allow,Deny
# Allow from all
#
<Directory "c:/wamp/apps/phpmyadmin3.3.9/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
I changed c:/ to d:/ as per the location of phpmyadmin on my machine and restarted all services. But I'm still getting the same error.
You need to configure your apache2.conf to make phpMyAdmin works.
sudo nano /etc/apache2/apache2.conf
Then add the following line to the end of the file.
Include /etc/phpmyadmin/apache.conf
Then restart apache
/etc/init.d/apache2 restart
When you install a new phpmyadmin, or anything at all that refreshes the state of the apache.conf, there is usually need to retrace all previous manual inclusions in the config file.
Hence, given that when phpmyadmin is installed like in this tutorial, you added a line in the /etc/apache2/apache2.conf it becomes necessary to repeat that step:
Hence, running the command
sudo nano /etc/apache2/apache2.conf
and the including the following line at the end of the opened config file
Include /etc/phpmyadmin/apache.conf
usually solves this problem.
Remember to hit CTRL+O to save your changes, and then CTRL+X to close the open file.
Lastly, restart apache to let your new configuration take effect:
sudo systemctl restart apache2
That's it!
Start wamp or xamp make sure the icon color change to green for wamp. This time open it in another browsers not Internet explorer . it should work

How to log page requests using Apache?

I am hosting some documents on my local machine using Apache for my group.
I have copied/linked the documents under /var/www/html.
Is there a way to log the requests with timestamps for each request?
Logging should already be enabled out of the box, and be logging to a file called access_log. I've never seen an install where it wasn't already turned on.
Usually the directive for where to log to is set in a file called httpd.conf.
Most of the time, the file is in /var/log/apache2.
Assuming your apache server is running and you have shell access:
do this:
genja ~ # ps aux |grep apache|tail -n1
root 23605 0.0 0.2 248636 10684 ? Ss Jun08 0:06 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D LANGUAGE -D MANUAL -D SSL -D SSL_DEFAULT_VHOST -D PHP5 -D PERL -D PROXY -D SCGI -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start
.. that is an apache daemon process. You are looking for "-f /etc/apache2/http.conf".
If your apache server was not told (by the distro init scripts) where to get the config file it will look in the default location which could be under: /etc/apache2/ or /etc/httpd/ (or anywhere else, really, but those two are most common). In that folder you will find a file called apache2.conf or httpd.confjust try this:
find /etc/ -iname httpd.conf -o -iname apache2.conf
Once you have located the configuration file for the apache server, look for the line where they include the modules configurations. On my system it looks like this:
Include /etc/apache2/modules.d/*.conf
Now you need to figure out where the log file is:
genja modules.d # grep CustomLog /etc/apache2/modules.d/*
00_mod_log_config.conf:# a CustomLog directive (see below).
00_mod_log_config.conf:CustomLog /var/log/apache2/access_log common
00_mod_log_config.conf:#CustomLog /var/log/apache2/referer_log referer
00_mod_log_config.conf:#CustomLog /var/log/apache2/agent_logs agent
00_mod_log_config.conf:#CustomLog /var/log/apache2/access_log combined
you are looking for: CustomLog /var/log/apache2/access_log common.
Note that this CustomLog directive could be in the main apache2.conf file too.
Now you have the location of the log file. The most likely thing to be stopping your server from logging now is file permissions. Make sure the directory given under CustomLog exists and that the apache server can write to it:
as root:
mkdir -p /var/log/apache2
touch /var/log/apache2/access_log
chown -R APACHEUSER /var/log/apache2
chmod 755 /var/log/apache2
chmod 644 /var/apache2/access_log
where APACHEUSER is likely to be apache or www or even httpd. You can figure that out by running:
genja ~ # ps aux |grep apache |awk '{print $1}'
apache
(...)
apache
root
So the user running the apache server on my system is actually called apache. It is not root. Or at least should not be.
restart your server after changing the permission of that file. I dont know how your distro does it. There is a service[s] command on ubuntu I think. But you can always run the init script directly:
/etc/init.d/apache restart (ir may be under a different location on your distro) just reboot the whole computer if you cant figure out how to restart the apache server.
If the access_log file is empty after you restarted the server change APACHEUSER to root in the above command.
after all this just use your favourite pager or text editor to look at the log. Or even tail -f to monitor it in real time. I hope this helps. gl.
I can imagine you have set up a virtual host (so called vhost) for your /var/www/html document root.
So you can just add your log set up requirements within that specific vhost, sothat you'll get a specific log file.
Like this example :
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName www.yourdomain.org
ServerAdmin webmaster#domain.de
<Directory "/var/www/html">
Options FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
# if you need some users basic authentication
# AuthType Basic
# AuthName "MY DOMAIN AUTHENTICATION"
# AuthUserFile ${APACHE_BASEDIR}/conf.d/special_users
# Require user foobar
</Directory>
# your log specific requirements
# LOGS (overwriting previous conf See /etc/apache2/apache2.conf)
# Possible values for LogLevel : debug, info, notice, warn, error, crit, alert, emerg.
LogLevel info
ErrorLog /var/log/apache2/my_special_error.log
# Option 1 (recommended): you merge these specific logs with the overall log file name and format
# CustomLog /var/log/apache2/access.log combined
# Or, Option 2: you set up a specific log file for that domain
LogFormat "%h %l %u %t \"%r\" %>s %b" my_special_access.log
CustomLog /var/log/apache2/my_special_access.log
</VirtualHost>
You will find the way the logs are formatted in the main apache configuration file, eg /etc/apache2/apache2.conf in debian's like distros. Or you take them as they are, or you overwrite them in your virtual host configuration. If you are not working with virtual hosts, that does not change much these principles.
Then you can manipulate the access.log file to extract, analyze, copy or do whatever you want with this. You can do that either in shell bash scripting (or perl or even python or C or...). I would recommend bash, that you can easily automatized as a cronjob.
LogFormat "%h %l %u %t \"%r\" %>s %b" mylog
CustomLog logs/doc_root_access_log mylog
which will output like below (the timestamp) to the log file doc_root_access_log
127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326
You should really refer here as they have plenties of explanation especially on the log modifier.