- 1 year ago
How to set up virtual hosts when changed the default port(80) to 8080?
To set up virtual hosts when you've changed the default port (80) to 8080, you'll need to configure your web server to handle incoming requests on port 8080 and direct them to the appropriate virtual hosts. Below are the general steps for setting up virtual hosts on popular web servers like Apache and Nginx:
Apache HTTP Server:
Ensure Apache is Listening on Port 8080: In your Apache configuration file (
httpd.conf
orapache2.conf
), look for theListen
directive and change it toListen 8080
. This will make Apache listen on port 8080 instead of the default port 80.Enable Virtual Hosts: Make sure the Apache server is set up to support virtual hosts. In the configuration file, you should have a section similar to this:
phpNameVirtualHost *:8080
<VirtualHost *:8080>
# Virtual Host Configuration
</VirtualHost>
Create Virtual Hosts: Define your virtual hosts inside the
<VirtualHost>
blocks. Each virtual host will have its own configuration, specifying theServerName
,DocumentRoot
, and any other specific settings.bash<VirtualHost *:8080>
ServerName www.example.com
DocumentRoot /path/to/website
# Other configurations for this virtual host
</VirtualHost>
Save the Configuration and Restart Apache: Save your changes to the Apache configuration file and restart Apache to apply the new settings.
bash# On Linux:
sudo service apache2 restart
# On Windows:
httpd -k restart
Nginx:
Ensure Nginx is Listening on Port 8080: In your Nginx configuration file (typically
nginx.conf
), look for thelisten
directive and change it tolisten 8080
. This will make Nginx listen on port 8080 instead of the default port 80.Create Virtual Hosts: Nginx uses a different approach for virtual hosts. Instead of separate blocks, it defines server blocks for each virtual host within the
http
block.arduinoserver {
listen 8080;
server_name www.example.com;
location / {
root /path/to/website;
# Other configurations for this virtual host
}
}
Save the Configuration and Restart Nginx: Save your changes to the Nginx configuration file and restart Nginx to apply the new settings.
bash# On Linux:
sudo service nginx restart
# On Windows (if you installed Nginx as a service):
nginx -s reload
After completing these steps, your virtual hosts should be set up to handle incoming requests on port 8080. Remember to replace www.example.com
with your actual domain name and adjust the paths as needed for your website's location.