How to access the web page using specific port?

5,687

If you want to do it manually, edit the file nano /etc/apache2/sites-enabled/000-default.conf

and change your virtual host configuration :

<VirtualHost *:80>
# [ Server Domain ]
ServerName www.domain.com
# [ Server Root ]
DocumentRoot /web/
# [ Prevent direct access to admin]
Redirect 301 /admin/ http://www.domain.com:8080
</VirtualHost >

Listen 8080
<VirtualHost *:8080>
# [ Server Domain ]
ServerName www.domain.com
# [ Server Root ]
DocumentRoot /web/admin/
</VirtualHost >

By the way sites-enabled/000-default.conf is a symbolic link of sites-available/000-default.conf

You should set your web site and admin site in two separate folder to have two clean virtual host, without protecting direct access with a redirect

You can set listening port in /etc/apache2/ports.conf instead of your website configuration if you want

Share:
5,687

Related videos on Youtube

user3274165
Author by

user3274165

Updated on September 18, 2022

Comments

  • user3274165
    user3274165 over 1 year

    I created two directories for storing the website on the web server

    /web
    /web/admin
    

    Assume that my website domain is http://www.domain.com/ and I would like to using the port 8080 for the admin page.

    How can I restrict the url http://www.domain.com:8080 point to /web/admin and the http://www.domain.com:80 still point to /web?

    I know most of web control panel doing like that. Can anyone guide me how I can do this?

    Here is my environment: Linux CentOS 7.0, Apache/2.4.6

  • Ole Wolf
    Ole Wolf over 8 years
    You'll also want to change the entries in the ports.conf file, which configures where Apache is listening. Look for the "Listen" directive.
  • Froggiz
    Froggiz over 8 years
    I edited the post, to add this information
  • Ole Wolf
    Ole Wolf over 8 years
    Oh, I didn't realize you had already placed a "Listen" directive in the web site configuration.
  • Froggiz
    Froggiz over 8 years
    I didn't you corrected me :P