In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to achieve multi-site configuration in Nginx, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Under the Nginx configuration directory, create a "vhost" directory. This example assumes that Nginx is installed by default and the configuration directory is in "/ etc/nginx"
$sudo mkdir / etc/nginx/vhost
Create a configuration file for siteA
$sudo vi / etc/nginx/vhost/vhost_siteA.conf
Enter the following configuration information
Server {listen 80; # listening port server_name www.siteA.com siteA.com; # site domain name root / home/user/www/blog; # site root index index.html index.htm index.php; # default navigation page location / {# WordPress fixed link URL rewrite if (!-e $request_filename) {rewrite (. *) / index.php }} # PHP configuration location ~\ .php$ {fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params;}}
Create siteB configuration files like siteA, with the only difference being the "server_name" and "root" directories
$sudo vi / etc/nginx/vhost/vhost_siteB.confserver {... Server_name www.siteB.com siteB.com; # site domain name root / home/user/www/forum; # site root directory.}
Open the nginx.conf file
Sudo vi / etc/nginx/nginx.conf
Add the configuration file of the virtual directory to the end of the "http {}" section
Http {... Include / etc/nginx/vhost/*.conf;}
Restart the Nginx service
$sudo service nginx restart
Visit www.siteA.com and www.siteB.com now and you will find that browsers will open different sites
Tips for forbidding access
If your Nginx root directory is set to "/ home/user/www", and you want to prevent others from accessing your site through "http://IP address / blog" or "http://IP address / forum", the easiest way is to disable IP address access. The methods are as follows:
1. Open the default configuration file of the Nginx website and remember to back it up first
$sudo cp / etc/nginx/sites-available/default / etc/nginx/sites-available/default_bak$ sudo vi / etc/nginx/sites-available/default
two。 Delete everything, leaving only the following configuration
Server {listen 80 default_server; server_name _; return 404;}
3. After restarting Nginx, others will not be able to access the website through the IP address
If you don't want to ban IP addresses from accessing the entire directory, just prevent others from accessing your blog and forum through IP. Then you need to disable directory access to "/ blog" and "/ forum".
1. Open the default configuration file of the Nginx website, as above, remember to back up first
two。 Add the following configuration to the "server {}" section
Location ^ ~ / blog/ {deny all;} location ^ ~ / forum/ {deny all;}
3. Just restart Nginx.
After reading the above, do you have any further understanding of how to implement multi-site configuration in Nginx? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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