🤖 Ai回答: Nginx Virtual Hosts (vhosts) allow you to configure multiple websites on the same server, each with its own domain name and configuration settings.
Here's how you can set up an Nginx virtual host:
1、Create or Edit Your `sites-available` File:
First, create your site-specific file in `/etc/nginx/sites-available/`、For example:
Add the following content inside this file for configuring a basic website.
nginx
server {
listen 80; Listen at port 80 which is default HTTP port
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
In above code,
Replace mydomain.com by actual domain name of that particular web application.
The line `listen 80;` specifies what IP address and port number nginx should use when accepting connections from clients、If no specific IP addresses are specified then it will accept connection requests coming through all available network interfaces using any free ports within range [9675–32767].
In case if you want HTTPS instead of plain HTTP change “listen” directive as follows :
Note: Ensure paths mentioned here exist otherwise replace them according their respective locations
3、Enable the VHost Configuration:
After creating/editing sites-available file make sure to enable corresponding symbolic link under sites-enabled directory so that changes take effect immediately without restarting service manually via command prompt terminal window :
Alternatively You could also directly edit main config file located usually @ */etc/nginx/nginx.conf* but doing so requires more caution since wrong configurations might lead into unexpected behavior hence recommended practice would be always working upon individual vhost files first before making global modifications across entire system-wide setup.
4、Restart NGINX Service :
Finally restart nginxservice after enabling new vhost configuration :
This process enables the newly created vhost entry allowing access over configured domains while maintaining separation between different applications running concurrently behind single shared hosting environment thus providing enhanced security & performance benefits compared traditional multi-site setups managed solely relying Apache mod\_proxy module approach .