Setting up virtual hosts on Nginx in an IPv6-only environment on an Alpine Linux VPS can be a bit tricky but fear not, I'll guide you through it step by step. Let's get started:
Step 1: Connect to Your VPS
First, ensure you have SSH access to your VPS. Once connected, make sure your system is up-to-date by running:
apk update && apk upgrade
Step 2: Install Nginx
Next, install Nginx on your Alpine Linux VPS:
apk add nginx
Step 3: Configure Nginx
Now, we need to configure Nginx to serve our virtual hosts.
3.1. Create Virtual Host Configuration Files
In this example, let's create two virtual hosts: example1.com
and example2.com
. Create configuration files for each:
nano /etc/nginx/conf.d/example1.com.conf
Add the following configuration for example1.com
:
server {
listen [::]:80;
server_name example1.com www.example1.com;
root /var/www/example1.com/html;
index index.html index.htm;
}
Create another configuration file for example2.com
:
nano /etc/nginx/conf.d/example2.com.conf
Add the following configuration for example2.com
:
server {
listen [::]:80;
server_name example2.com www.example2.com;
root /var/www/example2.com/html;
index index.html index.htm;
}
3.2. Create Web Root Directories
Create directories to store the website files for each virtual host:
mkdir -p /var/www/example1.com/html
mkdir -p /var/www/example2.com/html
3.3. Test Configuration and Restart Nginx
Test the Nginx configuration for syntax errors:
nginx -t
If there are no errors, restart Nginx to apply the changes:
rc-service nginx restart
Step 4: Set Up DNS Records
Ensure your domain names (example1.com
and example2.com
) have AAAA records pointing to your VPS IPv6 address.
Step 5: Create Sample Websites
Create sample index.html
files for each virtual host to test:
echo "Welcome to example1.com" > /var/www/example1.com/html/index.html
echo "Welcome to example2.com" > /var/www/example2.com/html/index.html
Step 6: Verify
Open a web browser and navigate to http://example1.com
and http://example2.com
. You should see the respective "Welcome" messages.
Additional Notes:
- Remember to replace
example1.com
and example2.com
with your actual domain names.
- Ensure that firewall settings allow traffic on port 80 (HTTP) and port 443 (HTTPS) if you plan to use SSL/TLS.
- Optionally, you can set up SSL/TLS certificates using Let's Encrypt for added security.
That's it! You've successfully set up virtual hosts on Nginx in an IPv6-only environment on Alpine Linux.