Run Apache and Nginx side by side

May 28th, 2015 § 0 comments § permalink

Recently I needed nginx and Apache side by side as one of our component was using nginx. Since now I am working on PHP, apache was my default server and it uses port 80. So when I installed nginx, it tries to use the same port 80 and failed to start. Now I need to run nginx in a different port other than 80.

So I decided to run nginx in port 8080. To change its default port, I updated the listen value in /etc/nginx/sites-enabled/default from 80 to 8080.

server {
        listen 8080 default_server;
        listen [::]:8080 default_server ipv6only=on;

After this change, I started running on port 8080 while my apache still running on 80. Thus I am able to run nginx and apache side by side.

Adding virtual host in apache on ubuntu

September 28th, 2011 § 0 comments § permalink

Here is the simple tutorial which helps to set up virtual host in apache on your Ubuntu. I assume you have a bit idea on apache and basic commands on ubuntu and vim. It also assumes that you already installed apache and vim.

  1. Create a file in /etc/apache2/sites-available

    To create a file in this location you need root privilege. so don’t forget to use sudo. You can give any valid file name (without any extension) except default and default-ssl. Use the following command to create it.

  2. Open the file.

    Here I am using vim editor for convenience. You can use any editor but make sure, you run the editor as root.

  3. Get into insert mode by pressing “i”.

    Skip this step if you are not using vim editor.

  4. Copy the following text into the editor

    You need to change the Document root (/home/phprepo/www/my-works) with the absolute path to your project folder.

    If you have already given to some other virtual host then you need to provide some other for this host. Now save and Quit the editor. You can use exit the insert mode using Esc and use “:wq” for save and exit.

  5. Enabling the virtualhost

    By step 5 you created the virtualHost. Now you need to enable it. You can use following command to enable it.You need to restart apache after enabling it.

    In future if you want to disable you can use sudo a2dissites my-works

  6. Restart apache

  7. Add virtual host to hosts file

    Open /etc/hosts and get into insert mode. paste the following line

    Since is already given to localhost you need to give a different one for our virtual host.But make sure you need to provide the same in the virtualhost file too.(<VirtualHost>)

Now take a web browser and type http://my-works/ this will redirect to your document root.