Nginx multi domain configuration method

  • 2020-05-13 04:41:06
  • OfStack

In many cases, multiple domain names need to be used, but you only have one server. How to set up a server so that one server can access the same domain name? The following method is to set up Nginx on the server and directly modify its configuration, as follows:


user www www; # The user name 
worker_processes 2;

error_log ../error.log;
#error_log logs/error.log notice;
pid    /usr/local/nginx/nginx.pid;

worker_rlimit_nofile 65535;
events 
{
  use epoll;
  worker_connections 65535;
}


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;

 server_names_hash_bucket_size 128;
 client_header_buffer_size 32k;
 large_client_header_buffers 4 32k;
 client_max_body_size 8m;

 sendfile on;
 tcp_nopush on;
 keepalive_timeout 60;
 tcp_nodelay on;
 fastcgi_connect_timeout 300;
 fastcgi_send_timeout 300;
 fastcgi_read_timeout 300;
 fastcgi_buffer_size 64k;
 fastcgi_buffers 4 64k;
 fastcgi_busy_buffers_size 128k;
 fastcgi_temp_file_write_size 128k;
 gzip on; 
 gzip_min_length 1k;
 gzip_buffers 4 16k;
 gzip_http_version 1.0;
 gzip_comp_level 2;
 gzip_types text/plain application/x-javascript text/css application/xml;
 gzip_vary on;

# The first 1 Individual domain name service 
 server 
 {
     listen  80;# Listen on port 
     server_name website1.com;# Server url 
     root /usr/local/nginx/html;# The site directory 
     index test.html test.htm test.php;# Url files 
 }

 # The first 2 Individual domain name service 
 server {
    listen 80;
    server_name website1.com;
    location / {
    #location  You can either not write it, or you can write it; But if you need to do more detailed configuration, you need to take advantage of it location
    root /usr/local/nginx/html1;# Site directory, you can define your own 
    index x264.html;    }
  }

# No access to the server IP Address access 
 server
 { 
   listen 80 default_server;
   server_name _;
   return 403;
 }

# allow IP Address corresponding to the domain name access 
server
 { 
   listen 80 default;
   server_name _;
   return 500;
 }
}

The above Nginx set up and configure the process if you have questions, you can view the other 1 article: / / www ofstack. com article / 122603. htm

Note: the domain name here must be exactly the same as the domain name you registered. Otherwise, the configuration will fail and the default index.html will be invoked, or Nginx will not be started.


Related articles: