In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to share with you how Nginx can efficiently deploy multiple sites on a server. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.
Let's take a look at our requirements. I have three website project projects that need to be deployed (corresponding to three domain names in turn). Provide a linux server to access the corresponding domain name and jump to the corresponding website.
Let's take a look at the architecture diagram I designed to solve this problem:
Here we assume that the public network ip of the linux server in the figure is 192.168.2.100, and then assume that we want to build three sites on this server: www.nginxtest.net, admin.nginxtest.net, and app.nginxtest.net.
All right, let's configure it in detail:
1. Configure nginx reverse proxy
Let's first connect to ssh, and then do the following (it is generally not recommended to modify the default main configuration file nginx.conf, so we create a new load balancer configuration file fxdl.conf to ensure server security, as shown below):
$ssh root@192.168.2.100 / / ssh connection # cd / usr/local/nginx/conf# touch fxdl.conf / / create an agent profile # vi fxdl.conf / / Open the file with the vi editor, and then press I on the keyboard
Note: in the vi editor, the keyboard presses I to enter insert state and esc to exit insert state.
Then enter the following configuration code (the domain name part is customized and changed to your own domain name, and the comments section is opened as needed):
# set low-privileged users, set the number of user nobody;# work derivative processes for security worker_processes 4 * set error file storage path # error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;# set pid storage path (pid is an important file in the control system) # pid logs/nginx.pid;# set the maximum number of connections events {worker_connections 1024 } http {# to set the log format log_format main'$remote_addr-$remote_user [$time_local] "$request"''$status $body_bytes_sent "$http_referer"''"$http_user_agent"$http_x_forwarded_for"; # to specify the storage path for log files access_log / data/wwwlogs/access_nginx.log main; # enable efficient file transfer mode sendfile on # prevent network blocking tcp_nopush on; # prevent network blocking tcp_nodelay on; # long connection timeout in seconds keepalive_timeout 65; # Hash table collision rate, default 1024, larger memory consumption, but hash key conflict rate will be reduced, retrieval speed will be faster types_hash_max_size 2048 # File extension and file type mapping table include / usr/local/nginx/conf/mime.types; # default file type default_type application/octet-stream; # include / etc/nginx/conf.d/*.conf; # is mainly used to set a set of proxy servers that can be used in proxy_pass and fastcgi_pass instructions. The default load balancing method is polling upstream tomcat_client {server localhost:8080 } # enable gzip compression. When enabled, the visited web page will automatically compress # gzip on; # specify the server name and parameter server {listen 80; server_name app.nginxtest.net; location / {proxy_pass http://tomcat_client; proxy_redirect default; # set proxy proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr }} server {listen 80; server_name admin.nginxtest.net; location / {proxy_pass http://tomcat_client; proxy_redirect default; proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr;}} server {listen 80; server_name www.nginxtest.net; location / {proxy_pass http://tomcat_client; proxy_redirect default Proxy_set_header host $host; proxy_set_header x-real-ip $remote_addr;} location = / {# determine whether it is mobile if ($http_user_agent ~ *'(iphone | ipod | ipad | android | windows phone | mobile | nokia)') {rewrite. Http://www.nginxtest.net/phone break;} rewrite. Http://www.nginxtest.net/pc break;}
All right, it's as simple as that. The nginx reverse proxy is configured. Configure tomcat below:
two。 Configure tomcat to deploy multiple sites
$ssh root@192.168.2.100 / / ssh connection # cd / usr/local/tomcat# cp / usr/local/tomcat/conf/server.xml / usr/local/tomcat/conf/server.xml_bk / / backup the original server.xml file # vi server.xml / / Open the file with the vi editor, and then press I on the keyboard
We edit the server.xml,engine node and add the following host node (the domain name and site project directory in the node need to be customized and modified to your own):
Note: if you want to directly access the public network ip without web pages, delete the
..
That's it.
Press esc when the input is complete, and then enter:
: wq!
You can save and exit the configuration file. At this point, the tomcat is also configured.
Then we can put our multi-site project code under / data/wwwroot/. Then start nginx and tomcat.
Now we can try visiting the second-level domain names www.nginxtest.net, admin.nginxtest.net, and app.nginxtest.net of each site, and we find that we can jump to the corresponding site (the same effect as deploying a server for each site).
These are all the contents of the article "how Nginx can efficiently deploy multiple sites on one server". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.
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.