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 set up nginx virtual host

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "nginx virtual host how to set up", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "how to set up nginx virtual host" this article.

Several virtual hosts are supported on the 1.http service. Each virtual host has a corresponding server configuration item, which contains the configuration related to the virtual host. Reference article, https://blog.csdn.net/liqi_q/article/details/78799121.

two。 What is a virtual host

The virtual host uses special software and hardware technology, which divides a server host running on the Internet into "virtual" hosts.

Each virtual host can be an independent website with an independent domain name and complete Intemet server functions (WWW, FTP, Email, etc.).

Virtual hosts on the same host are completely independent.

From the point of view of website visitors, each virtual host is exactly the same as a separate host.

With virtual hosts, you do not have to provide a separate Nginx server or run a separate set of Nginx processes for each site you want to run.

Virtual hosts provide the ability to run multiple websites on the same server and the same set of Nginx processes.

The content contained in the 3.server is as follows:

Listen listening port, default is 80

Server_name server name, such as localhost, www.example.com

Configure virtual hosts supported by pure static html, as shown below:

Nginx server ip address: 192.168.64.132

Step 1: vim / etc/nginx/nginx.conf, add the following:

If the default listening port is 80, you don't have to write listen 80; it's OK.

Root / soft/code/www; in server is the default site root location that defines the virtual host, and index index.html; is the default home file. If there are multiple index, they match from left to right, and if the first one cannot be opened, the second one will be opened.

Step 2: nginx-t-c / etc/nginx/nginx.conf automatically checks the newly modified configuration file for errors. If the file is not specified by-c, the main configuration file nginx.conf is checked by default.

Step 3: create a directory, mkdir / soft/code/ {www,blog}, and create an index.html file in the newly created directory.

Step 4: if you are accessing the virtual host from another machine, you need to configure domain name resolution.

Vim / etc/hosts, add content as shown below:

Step 5: start nginx, enter nginx without any parameters to start nginx. The default listening port is 80. Check whether port 80 is enabled by the way. The command is as follows: netstat-ntulp | grep 80

Step 6: test whether the virtual machine is set up successfully or not. If you test it on the nginx server, you can do this:

When curl www.test.com.zai tests the virtual host on other machines, you can enter the domain name directly into the browser: for example: www.test.com.

The above is all the contents of the article "how to set up the nginx virtual host". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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

Development

Wechat

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

12
Report