nginx domain binding domain, nginx domain binding port
I. nginx domain binding Domain nginx bind multiple domains can also write multiple domain rules in a configuration file, but also can create multiple domain configuration files separately, I generally build a file for each domain for ease of management, some similar domains can also be written in a total configuration file. I. Writing one file per domain First opennginx Domain Name Profile Storage Directory:/usr/local/nginx/conf/servers , If you want to bind a domain namewww.itblood.com then create a file in this directory:www.itblood.com.conf Then write rules in this file, as if:
server{ listen 80; server_name www.itblood.com; #Binding Domain index index.htm index.html index.php; #default file root /home/www/itblood.com; #website root directory include location.conf; # Call other rules, also remove }
Then restart the nginx server, and the domain name is bound successfully nginx server restart command: /etc/init.d/nginx restart Second, a file more than one domain name The rules for adding multiple domains to a file are the same, just write down the above individual domains repeatedly, e.g.
server{ listen 80; server_name www.itblood.com; #Binding Domain index index.htm index.html index.php; #default file root /home/www/itblood.com; #website root directory include location.conf; # Call other rules, also remove } server{ listen 80; server_name msn.itblood.com; #Binding Domain index index.htm index.html index.php; #default file root /home/www/msn.itblood.com; #website root directory include location.conf; # Call other rules, also remove }
Third, the domain name without www plus 301 hops If the domain name without www to add a 301 jump, that is also the same as binding the domain name, first binding the domain name without www, just do not have to write the site directory, but a 301 jump, such as.
server { listen 80; server_name itblood.com; rewrite ^/(.*) http://www.itblood.com/$1 permanent; }
Four, add 404 pages
Add 404 pages, can be added directly in it, such as:
server{ listen 80; server_name www.itblood.com; #Binding Domain index index.htm index.html index.php; #default file root /home/www/itblood.com; #website root directory include location.conf; # Call other rules, also remove error_page 404 /404.html; }
nginx domain binding port
server { listen 80; server_name taqing.me www.taqing.me; ##, bind the domain name location / { proxy_pass http://127.0.0.1:8000; ## Specify port number 8000 }