In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how nginx can access multiple websites on one server". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
On one server, visit different websites
There are usually two ways to distinguish:
1. Port number that is monitored
two。 Through the domain name
1. Access different hosts through ports:
Configuration file for nginx:
/ usr/local/nginx/conf/nginx.conf
Centos file default encoding format latin1
The command to view the encoding format:: set fileencoding
# user nobody;worker_processes 1 Chinese errorists log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024;} # # A http node http {include mime.types; default_type application/octet-stream # log_format main'$remote_addr-$remote_user [$time_local] "$request" #'$status $body_bytes_sent "$http_referer" #'"$http_user_agent"$http_x_forwarded_for"; # access_log logs/access.log main; sendfile on; # tcp_nopush on; # keepalive_timeout 0; keepalive_timeout 65; # gzip on # server node, that is, the configuration you need to access the website # A server node is the port number of a virtual host server {listen 80; # listening. The default for accessing the website is port 80 server_name localhost; # that is, the domain name # charset koi8-r; # access_log logs/host.access.log main; location / {# location root html # locate the html folder under the nginx root directory index index.html index.htm; # set the home page of the website}
Multiple server can be configured at this time, that is, different hosts are configured.
Add virtual host: (distinguished by port number)
Server {listen 81; server_name localhost; # charset koi8-r; # access_log logs/host.access.log main; location / {html81 folder index index.html index.htm; ``} newly created under the root directory of root html-81; # nginx
After editing the file, we reload the configuration file
Through the command:. / nginx-s reload
Effect:
We know that when multiple websites are configured on a server, it is impossible to distinguish them by port number, so next I need to distinguish them by domain name.
two。 Distinguish different virtual hosts by domain name
What is a domain name?
The domain name is the URL.
For example: www.baidu.com
Usually when we access the domain name, we need to resolve the domain name through the dns server
Dns server: resolves domain names to ip addresses. What is saved is the mapping between the domain name and ip.
A domain name corresponds to an ip address, and an ip address can be bound by multiple domain names.
Local tests can modify the hosts file.
Modify the hosts file of window: (C:\ windows\ system32\ drivers\ etc)
You can configure the mapping relationship between domain name and ip. If the corresponding relationship between domain name and ip is configured in the hosts file, you do not need to go to the dns server!
Continue to configure under the nginx.conf file you just had:
Server {listen 80; server_name www.taobao.com; # charset koi8-r; # access_log logs/host.access.log main; location / {root html-taobao; index index.html index.htm;}} server {listen 80; server_name www.baidu.com; # charset koi8-r; # access_log logs/host.access.log main; location / {root html-baidu Index index.html index.htm;}
Configuration of domain name:
192.168.25.148 www.test.com
192.168.25.148 www.yiyou.com
Restart the nginx service
Observe the effect:
This is the end of the content of "how nginx can access multiple websites on one server". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.