How to set up Masked Redirect with Google Cloud VM instances - google-compute-engine

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

Related

How to renew Lets encrypt certificate in ejabberd configured server?

How to renew Lets encrypt certificate in ejabberd configured server? My server is Debian-jessie and I have tried to renew SSL certificates using the below command,
certbot certonly -d mydomainname
But it produced an unexpected error:
Failed authorization procedure. : urn:acme:error:connection ::Timeout
during connect (likely firewall problem). Skipping.
Timeout during connect (likely firewall problem)
To fix these errors, please make sure that your domain name was
entered correctly and the DNS A record(s) for that domain
contain(s) the right IP address. Additionally, please check that
your computer has a publicly routable IP address and that no
firewalls are preventing the server from communicating with the
client. If you're using the webroot plugin, you should also verify
that you are serving files from the webroot path you provided.
Found the proper answer for this:
You need to stop the service ejabberd service before you do the
process,
service ejabberd stop
Then move the expired ssl pem file to somewhere else,
mv /etc/ejabberd/ejabberd.pem /etc/ejabberd/ejabberd.pem.backup
Go to the directory where the cert boot locating,
cd /root
Enter the below command in-order to renew the certificate for the
required domain
certbot certonly --webroot -w /etc/ejabberd -d yourdomain.com --force-renewal --rsa-key-size 4096
Then merge the generated ssl files to the ejabberd configuration file
cat /etc/letsencrypt/live/yourdomain.com/privkey.pem /etc/letsencrypt/live/chat.yourdomain.com/fullchain.pem > ejabberd.pem
Then move the pem file to the ejabberd root path
mv ejabberd.pem /etc/ejabberd
chown ejabberd /etc/ejabberd/ejabberd.pem
Enable ejabberd service
service ejabberd start
service ejabberd status

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.

Subdomain with port number in Ubuntu 12.04 (Precise Pangolin)

I have created subdomain in my DNS server. How can I set each subdomain so that it only accepts connections via a particular port?
For example: ftp.example.com → only accepts connections that come from port 21
You can set port restrictions using iptables.
You can also set port restrictions on the server itself and it depends on your server architecture. If you're running Apache, then you should take a look at defining a virtual host (vhost).
Just for illustration sake:
<VirtualHost *:21>
ServerAdmin webmaster#example.com
ServerName ftp.example.com
# Index + Directory root
DirectoryIndex index.php | index.html
DocumentRoot /var/www/path/to/site
</VirtualHost>
See that "*:21" - that's the port number.
Generally speaking, ftp.example.com would probably still redirect to your server's root directory.

How to put wildcard entry into /etc/hosts?

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";
}

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.