Configure Apache Different Port to Use Virtual Hosts on Ubuntu Server

By default, linux apache on use

Default document directory is: /var/www

The default port is: 80

If you want to publish your own a system resource directory, you can use the following method, execute the following command

Setp 1 Add a listening port

$ cd /etc/apache2
$ sudo vim ports.conf

Add in file

NameVirtualHost *:81
Listen 81
<IfModule dir_module>
        DirectoryIndex index.php default.php index.html
</IfModule>

Step 2 Configure the virtual directory

$ cd /etc/apache2/sites-available
$ sudo cp default default-me
$ sudo vim default-me

Document reads as follows

<VirtualHost *:81>
    ServerAdmin webmaster@localhost
 
    DocumentRoot /var/www/wwwroot
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/wwwroot/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>
 
    ErrorLog /var/log/apache2/error.log
 
    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn
 
    CustomLog /var/log/apache2/access.log combined
 
</VirtualHost>

Step 3 Publishing Site

$ sudo a2ensite default-me

Step 4 Restart Service

$ sudo /etc/init.d/apache2 restart

Step 5 Test

If you can normally access http://localhost:81 means that the correct configuration.

0.00 avg. rating (0% score) - 0 votes