Home > Web Front-end > JS Tutorial > How to configure multi-site vhost in Nginx

How to configure multi-site vhost in Nginx

亚连
Release: 2018-06-13 14:05:43
Original
1928 people have browsed it

This article mainly introduces the method of configuring multi-site vhost in Nginx. Friends who need it can refer to it

Assuming that you want to use different domain names to access different directories in Linux Nginx, you need to configure it at this time Multiple vhosts, the specific configuration is as follows, assuming that the website root directory is set to /var/www/

1, create two new directories under /var/www/

/var/www/ushark.net
/var/www/ushark.wang
Copy after login

2, edit/ etc/nginx/nginx.conf

http {
  include    /etc/nginx/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 /var/log/nginx/access.log main;
  sendfile    on;
  #tcp_nopush   on;
  keepalive_timeout 65;
  #gzip on;
  include /etc/nginx/conf.d/*.conf;   #主要是加入此行,如有则忽略
}
Copy after login

3. Create two new conf files under /etc/nginx/conf.d.

/etc/nginx/conf.d/ushark.net.conf
/etc/nginx/conf.d/ushark.wang.conf
Copy after login

4. Copy the following configuration information to the two files. , just modify the red part!!! The server_name is consistent with root, that is, the directory and domain name correspond one to one!!!

server {
  listen    80;
  server_name  www.ushark.net;
  #charset koi8-r;
  #access_log /var/log/nginx/host.access.log main;
  root  /var/www/ushark.net/;
  if (!-e $request_filename){   # rewrite可根据网站需要增删
      rewrite ^/(.*) /index.php last; 
  } 
  location / {
    index index.php index.html index.htm;
  }
  #error_page 404       /404.html;
  # redirect server error pages to the static page /50x.html
  #
  error_page  500 502 503 504 /50x.html;
  location = /50x.html {
    root  /var/www/ushark.net/;
  }
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  #
  #location ~ \.php$ {
  #  proxy_pass  http://127.0.0.1;
  #}
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  location ~* \.php$ {
    fastcgi_index  index.php;
    fastcgi_pass  127.0.0.1:9000;
    include      fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  SCRIPT_NAME    $fastcgi_script_name;
  }
  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  #location ~ /\.ht {
  #  deny all;
  #}
}
Copy after login

5. Restart Nginx

systemctl restart nginx
Copy after login

6. Edit /etc/hosts ! !! Core steps!!!

[root@bogon ~]# vi 127.0.0.1    localhost.localdomain localhost
::1       localhost6.localdomain6 localhost6
127.0.0.1    www.ushark.net
127.0.0.1    www.ushark.wang
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Using ui-route to implement multi-layer nested routing in AngularJS (detailed tutorial)

About vue How to implement secondary linkage and select the first value by default

Use js to implement the box pushing game (detailed tutorial)

The above is the detailed content of How to configure multi-site vhost in Nginx. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template