Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure multiple virtual hosts in nginx

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of nginx how to configure multiple virtual hosts, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to configure multiple virtual hosts in nginx. Let's take a look.

It is very convenient to configure the virtual host vhost under nginx. You can mainly add a server to the configuration file nginx.conf of nginx

For example, I want to configure two virtual hosts, which can be accessed through the domain name linux.com and linux2.com. The corresponding directories are / usr/htdocs/linux and / usr/htdocs/linux2 (this directory is for your development project files)

Because I installed the local virtual machine, I first added two redirects to the hosts file:

192.168.20.250 linux.com / / 192.168.20.250 is the ip of my virtual machine, using the bridge method

192.168.20.250 linux2.com

Here we go: for example, configuring linux.com, configuring multiple virtual hosts is exactly the same process.

1. Find the configuration file nginx.conf of nginx

Usually in the conf file under the installation path of nginx

Enter the conf directory and see a lot of configuration files

Edit nginx.conf

Add a server {}, and the configuration in each server corresponds to a virtual host vhost

Server {listen 80; / / 80 port server_name linux.com; / / set the domain name # directly enter the directory entered by the domain name and the default parsed file location / {index index.html; root / usr/htdocs/linux / / entering linux.com directly comes here. Generally, the directory where the php is configured and parsed has been} # parsing the .php file location ~\ .php$ {fastcgi_pass 127.0.0.1 location 9000; fastcgi_index index.php; fastcgi_param script_filename / usr/htdocs/linux/$fastcgi_script_name; / / the directory corresponding to the current virtual host include fastcgi_params;}}

Add in nginx.conf

Add the file index.php under the corresponding / usr/htdocs/linux for testing

Restart nginx:service nginx restart

After modifying the configuration file of nginx, you need to restart nginx to take effect.

Open a browser and enter the domain name to test:

This is the end of the article on "how to configure multiple virtual hosts in nginx". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to configure multiple virtual hosts in nginx". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report