how to create multiple ports for apache on amazon EC2? - apache

I have Ubuntu 32 bit AMI(amazon machine image) on amazon cloud.
I have installed the LAMP stack on it.
apache: 2.4.7
mysql: 5.5.38
php: 5.5.9
Above are specification for A-M-P
Then I got the one public IP address.(x.x.x.x)
Now I need to create the multiple ports.
LIKE
x.x.x.x:81
x.x.x.x:82
is it possible??
I have done some steps for the ports configuration as follows:
vim /etc/apache2/ports.conf ==> add line Listen 81
in virtual host file
<VirtualHost *:81>
-------
</VirtualHost>
vim /etc/apache2/hosts ==> added line 127.0.0.1 vhost_name
sudo a2ensite vhost_file_name.conf
sudo /etc/init.d/apache2 restart

Follow these instructions:
EC2 Instance
Update Apache
File: /etc/apache2/ports.conf
Listen 80
Listen 81
Listen xx where xx is a valid port number
Add/Update Virtual Host
Create a virtual host that listens to 81 or the port number that Apache is listening to.
Enable the site with sudo a2ensite name of the conf without .conf
Restart the apache sudo service apache2 restart
Amazon Console
Find the security group of the instance on the instances list.
Go to Security Group (find it on the LHS meun) and add the rules to allow the external world to talk to the port numbers your apache is listening to. Please follow this link to add the rules.

Related

Config VirtualHosts on Debian/Apache

On my debian/apache server at http://localhost I'm redirected to my api on port 3000 (this is ok)
Now I would like to open another port (8090), in http://localhost:8090 redirected to /var/www/html/
How to make?
Find the default virtual host conf file by running
ls /etc/apache2/sites-available/
There should be a file called deault.conf, or similar. We want to edit this file
sudo nano /etc/apache2/sites-available/default.conf
Make sure that apache actually is listening to your port 8090 by adding, to the top of that document
Listen 8090
Change the rest of the conf file to match your site, so it may look something like this
Listen 8090
<VirtualHost *:8090>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
# Other directives here
</VirtualHost>
Save the file with a different name in the same folder. The files must end with ".conf". Add the virtual host to enabled sites by running
sudo a2ensite virtual_host_file_name.conf
replacing "virtual_host_file_name.conf" with the name of the file you select in the previous step.
Then restart the apache server
sudo service apache2 reload
It seems like you're only interested in accessing it from localhost, but if you want to access it remotely you might need to check your firewalls.

Apache version conflict (cont)

Concerning the post Apache versions conflict. I tried again the installation of apache following the steps from https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions
I still have some problems if I want to test localhost from my local Site folder.
Result of apache log
Regarding the error
Could not reliably determine the server's fully qualified domain name,
using 127.0.0.1. Set the 'ServerName'...
I tried the option of adding ServerName localhost in the file /etc/apache2/apache2.conf https://askubuntu.com/questions/454497/apache2-could-not-reliably-determine-the-servers-fully-qualified-domain-name but I don't know if that is that is the right file, because i'm working with apache 2.4 (/usr/local/etc/apache2/2.4/httpd.conf)
Additionally, if I run the command sudo apachectl -k restart I got this
(48)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
In my file /etc/apache2/httpd.conf
I have this:
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User amhg
Group staff
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName localhost
DocumentRoot /Users/amhg/Sites
<Directory /Users/amhg/Sites>
#
AllowOverride All
and I uncommented LoadModule rewrite_module libexec/mod_rewrite.so
Any suggestions?
Thank you in advance!
you can see all of your apache installed version with command :
rpm -qa | grep httpd
in your log file I do not see any error.
can you sent all of your log file?
and can you explain what do you see in browser when go to :
http://localhost

GitLab: How to use ONLY Apache2 and skip nginx?

I am running GitLab on Port 81 today and I need it to run on Port 80 or 443 so that I can access it from office. Problem is that I already host other services using Apache2 on both those ports.
I have tried for hours and hours to do a proxy forward of GitLab from Apache2 host:80/gitlab to host:81 (where nginx is hosting gitlab) without success. I just keep getting problems thanks to the added folder /gitlab in the URL.
So I am in the idea of selfhosting gitlab under my Apache2 server instead. I am thinking of this approach:
Create symlink to webroot of gitlab from /home/www/sites/gitlab
Set up a vhost in Apache on port 81 to point to above symlink.
Enable Apache2 to listen on port 81.
Verify that GitLab functions properly on port 81 using Apache2.
Once confirmed, set up a proxy forward from my Apache2 Port 80 under subdir /gitlab to forward to the new Apache2 Port 81 now hosting GitLab.
What I need to know now is:
Is it possible to completely host gitlab on your own Apache2?
What is necessary to enable in Apache2 virtual host dir? Or other configs? Ruby etc?
Where is the webroot of github index documents etc?
What do you think of permission issues? Will I see any problems?
Thank you all in advance!

Chef Apache2 recipe on RHEL: ServerName not defined in the default recipe

I am using Chef to build out a virtual machine on Rackspace. The VM is a RHEL 6.5 box.
I am running into problems building the default Apache2 /etc/httpd/conf/httpd.conf file cleanly for RHEL using the Apache2 recipe (it appears to default to an Ubuntu flavor configuration).
In the recipe config template (apache2/templates/default/apache2.conf.erb) there is no place to define ServerName. Consequently when I test Apache is working properly I get the following
% apachectl configtest
httpd: Could not reliably determine the server's fully qualified domain name, using ##### for ServerName
Syntax OK
where ##### is my DNS, listed in my /etc/hosts and defined in my cookbook recipe attributes/default.rb file as servername.
If I look in the recipe template I don't see any location for the variable ServerName (first 17 lines):
#
# Generated by Chef
#
# Based on the Ubuntu apache2.conf
ServerRoot "<%= node['apache']['dir'] %>"
#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
<% if %w[debian].include?(node['platform_family']) -%>
LockFile /var/lock/apache2/accept.lock
<% elsif %w[freebsd].include?(node['platform_family']) -%>
LockFile /var/log/accept.lock
<% else %>
LockFile logs/accept.lock
<% end -%>
Now, if I manually go and edit /etc/httpd/conf/httpd.conf, adding a ServerName variable, everything works. Relevant before and after below:
BEFORE
#
# Generated by Chef
#
# Based on the Ubuntu apache2.conf
ServerRoot "/etc/httpd"
AFTER
#
# Generated by Chef
#
# Based on the Ubuntu apache2.conf
ServerRoot "/etc/httpd"
ServerName #####:80
Now when I test Apache:
% apachectl configtest
Syntax OK
Obviously the whole point of using Chef is to not hand edit configuration files, and whenever I rerun my chef recipe with chef-solo I am going to blow this customization away. I am so new to Chef that I don't really want to fork the cookbook on Github and make a new template for RHEL, but maybe that's what I need to do?
I am hoping there is just one configuration setting in my overall recipe I am not defining, that will add this variable to my core Apache httpd.conf file.
Hopefully someone with more experience with Chef, and in particular the Apache2 cookbook, can help me. Thanks in advance.
EDIT #1
A look at netstat -tulpn shows that I think Apache (httpd) is actually working, or at least listening in on port 80:
% netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1274/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1677/master
tcp 0 0 **.***.*.***:3306 0.0.0.0:* LISTEN 1585/mysqld
tcp 0 0 :::80 :::* LISTEN 6663/httpd
tcp 0 0 :::22 :::* LISTEN 1274/sshd
tcp 0 0 ::1:25 :::* LISTEN 1677/master
Is it looking more and more like a networking (DNS) issue?
EDIT #2
Based on the helpful comments to my original post I think I originally misdiagnosed this. I just built a new Ubuntu VM and installed Apache2 by hand using sudo apt-get install apache2 (ie. not using chef-solo) and I see the same installed layout of apache2 that my Chef recipe created on my RHEL VM. I also get the same warning when running apachectl configtest:
apache2: Could not reliably determine the server's fully qualified domain name, using ##### for ServerName
Syntax OK
When I point the browser on Ubuntu to 127.0.0.1:80 I see the 'It works!' standard Apache response. So, my issue is not really an issue. My thinking now is that this is a network problem. iptables?
EDIT #3
I just ssh'd into my RHEL VM and installed Firefox. I then opened it up and pointed it to 127.0.0.1:80 and I get the default page. I think this categorically confirms that I have a DNS issue. Time to speak to my networking admin.
As per the helpful comments from users cassianoleal and StephenKing, this "error" was actually a red herring. It is just an Apache warning that has no effect on if httpd is actually running or not.
The problem was really that I wasn't updating my iptables config. Once I installed the Chef cookbook simple_iptables and added a simple_iptables_rule to my Chef recipe to update my iptables to listen on ports 80 and 443, everything worked.
Live and learn I guess.
For the record, Chef is highly recommended if you aren't using it yet!

How do I configure apache2 to a port other than port 80?

I have installed apache2 on ubunto and have messed around with the text on the localhost page. Now I'm being asked to show it running on a port other than port 80. How do I do that?
You should change the line Listen x in your httpd.conf where x is the port number. You'll need to restart your apache server after that.
In the file: /etc/apache2/httpd.conf
change the following line:
Listen 80
to:
Listen <NEWPORT>
After that you need to restart the apache server:
sudo service apache2 start
UPDATE: Looks like with Ubuntu, the default /etc/apache2/httpd.conf is empty and the recommended approach is to create a new .conf file under /etc/apache2/conf.d so that even with software updates, the user changes are persistent.
So just create a new file say /etc/apache2/conf.d/mycustomizations.conf
Listen <NEWPORT>