Nginx配置多站點(diǎn)vhost的方法

假設(shè)你想在Linux Nginx中用不同的域名訪問不同的目錄,這時就要配置多個vhost,具體配置如下,假設(shè)網(wǎng)站根目錄設(shè)定在/var/www/

專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計、成都網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)田林免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了成百上千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。

1、在/var/www/下新建兩個目錄

/var/www/ushark.net
/var/www/ushark.wang

2、編輯/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;  ?。V饕羌尤氪诵?,如有則忽略
}

3、在/etc/nginx/conf.d下新建兩個conf文件,

/etc/nginx/conf.d/ushark.net.conf
/etc/nginx/conf.d/ushark.wang.conf

4、復(fù)制如下配置信息到兩個文件中,只要修改紅色部分內(nèi)容  !!! server_name與root保持一致即目錄和域名一一對應(yīng) !!!

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){  ?。!ewrite可根據(jù)網(wǎng)站需要增刪
      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;
  #}
}

5、重啟Nginx

systemctl restart nginx

6、 編輯/etc/hosts  !!! 核心步驟 !!!

[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

總結(jié)

以上所述是小編給大家介紹的Nginx 配置多站點(diǎn)vhost 的方法,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的!

分享名稱:Nginx配置多站點(diǎn)vhost的方法
標(biāo)題網(wǎng)址:http://bm7419.com/article28/ijhejp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站網(wǎng)站改版、網(wǎng)站導(dǎo)航、服務(wù)器托管網(wǎng)站策劃、面包屑導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)