How to Upload a File to an Ip/port

Tabular array of Contents

  • Introduction
  • Requirements
  • Prepare multiple IP addresses on a single network interface
  • Set multiple instances of Apache
  • Create the directory structure
  • Create test spider web pages for each virtual host
  • Ready ownership and permissions
  • Create virtual host files
  • Permit Apache through the firewall
  • Exam the virtual hosts

Introduction

Virtual hosting is a method for hosting multiple websites on a single car. There are ii types of virtual hosting: Proper name-based virtual hosting and IP-based virtual hosting. IP-based virtual hosting is a technique to utilise dissimilar directives based on the IP address and port a request is received on. Y'all can assign a separate IP for each website on a unmarried server using IP-based virtual hosting. This is mainly used to host different websites on dissimilar ports or IP addresses.

In this article we volition exist creating:

            Example 1: IP-based hosting URL: www.ip-vhost.com IP address: 192.168.1.42 Port: 80  Example 2: Port-based hosting URL: www.port-vhost.com  IP address: 192.168.i.43` Port: 8080                      

Requirements

  • A server running CentOS five. 7 with Apache installed
  • A desktop auto running Linux
  • A static IP accost for each site you want to host.

Gear up multiple IP addresses on a unmarried network interface

To set upwardly IP-based virtual hosting, yous need to have more than one IP address assigned to your server. Setting up multiple IP addresses on a unmarried network interface is called "IP aliasing." Information technology is very useful, particularly if your server but has one network interface card (NIC).

To set upwardly multiple IPs, you lot demand to edit the ifcfg-eth0 file:

            sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0                      

Add/edit the following lines:

            DEVICE="eth0" ONBOOT=yes BOOTPROTO=static IPADDR0=192.168.1.42 IPADDR1=192.168.1.43 NETMASK=255.255.255.0 GATEWAY=192.168.1.i DNS1=8.8.eight.8                      

Save and close the file when yous are finished. So restart the network service to make these changes take issue.

            sudo service network restart                      

Ready upward multiple instances of Apache

Past default Apache listens for incoming connections on port 80. For port-based virtual hosting, y'all demand to tell Apache to listen for IP address 192.168.one.42 on port 80 and for IP address 192.168.one.43 on port 8080.

To set up multiple ports, yous demand to edit the httpd.conf file:

            sudo nano /etc/httpd/conf/httpd.conf                      

Add/edit the post-obit lines:

            Listen 192.168.1.42:lxxx Listen 192.168.ane.43:8080                      

Relieve and close the file, so restart Apache to make these changes take effect.

            sudo systemctl restart httpd                      

Create the directory structure

First, you need to make a directory construction which volition hold the web pages. This directory is known equally "certificate root" for the domain.

In CentOS seven the default Apache document root directory is /var/www/html/.

Now, create 2 directory for websites world wide web.ip-vhost.com and world wide web.port-vhost.com in the default Apache document root directory:

            sudo mkdir -p /var/www/html/www.ip-vhost.com sudo mkdir -p /var/www/html/www.port-vhost.com                      

Create examination web pages for each virtual host

Now, you need to create an index.html file for each website which will place that specific domain.

Let'due south create an index.html file for the www.ip-vhost.com ip virtual host.

            sudo nano /var/www/html/world wide web.ip-vhost.com/index.html                      

Add the following content.

            <html>  <head>   <title>www.ip-vhost.com</title> </caput>  <body>   <h1>The ip-vhost.com virtual host is working!</h1> </trunk>  </html>                      

Save and shut the file when y'all are finished.

Similarly, create an index.html file for the www.port-vhost.com virtual host.

            sudo nano /var/world wide web/html/www.port-vhost.com/alphabetize.html                      

Add the following content.

            <html>  <head>   <title>www.port-vhost.com</championship> </head>  <trunk>   <h1>The port-vhost.com virtual host is working!</h1> </trunk> </html>                      

Save and close this file equally well. At present, you have the pages to exam the virtual host configuration.

Set up ownership and permissions

In CentOS 7 by default the Apache service runs equally the user apache. Yous must modify the ownership of these two virtual directories to apache, so that Apache can read and write data.

Y'all can change the ownership with chown command.

            sudo chown -R apache:apache /var/world wide web/html/world wide web.ip-vhost.com sudo chown -R apache:apache /var/www/html/world wide web.port-vhost.com                      

You should too make the Apache document root /var/www/html directory globe readable, and so that anybody can read files from that directory.

            sudo chmod -R 755 /var/world wide web/html                      

At present your web server has the permissions it needs to serve content.

Create virtual host files

The next pace is to create a virtual host configuration file for each website. The name of each configuration file must cease with .conf.

Let's create a virtual host file for website www.ip-vhost.com.

            sudo nano /etc/httpd/conf.d/ip-vhost.com.conf                      

Add the following content.

            <VirtualHost 192.168.1.42:80>    ServerName www.ip-vhost.com   ServerAlias ip-vhost.com   DocumentRoot /var/www/html/world wide web.ip-vhost.com   ErrorLog /var/www/html/www.ip-vhost.com/mistake.log   CustomLog /var/www/html/world wide web.ip-vhost.com/admission.log combined  </VirtualHost>                      

Save and close the file when you are finished.

Similarly, create a virtual host file for website world wide web.port-vhost.com.

            sudo nano /etc/httpd/conf.d/port-vhost.com.conf                      

Add the post-obit content.

            <VirtualHost 192.168.1.42:8080>    ServerName world wide web.port-vhost.com   ServerAlias port-vhost.com   DocumentRoot /var/www/html/www.port-vhost.com   ErrorLog /var/www/html/world wide web.port-vhost.com/error.log   CustomLog /var/www/html/www.port-vhost.com/access.log combined  </VirtualHost>                      

When you lot are finished, it is a good idea to check the syntax of the configuration. Y'all tin can check the syntax of files with the following command:

            sudo apachectl configtest                      

After the syntax check is done, restart Apache to make these changes have outcome.

            sudo systemctl restart httpd                      

Allow Apache through the firewall

Now, you lot need to allow the Apache port 80 and 8080 using FirewallD.

You can practice this past running post-obit commands:

            sudo firewall-cmd --permanent --add together-port=80/tcp sudo firewall-cmd --permanent --add-port=8080/tcp                      

Now, reload the firewall service for the changes to accept effect.

            sudo firewall-cmd --reload                      

Test the virtual hosts

At present on the desktop Linux figurer, open your web browser and go to the URLs http://192.168.1.42:80 and http://192.168.one.43:8080. You should come across sample pages that expect like this:

world wide web.ip-vhost.com sample page:

Sample page for vhost 1

www.port-vhost.com demo folio:

Sample page for vhost 2

lopezoppers.blogspot.com

Source: https://devops.ionos.com/tutorials/how-to-set-up-ip-and-port-based-virtual-hosting-vhosts-with-apache-web-server-on-centos-7.html

0 Response to "How to Upload a File to an Ip/port"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel