Nginx 配置多站點(diǎn)vhost 的方法
假設(shè)你想在Linux Nginx中用不同的域名訪問(wèn)不同的目錄,這時(shí)就要配置多個(gè)vhost,具體配置如下,假設(shè)網(wǎng)站根目錄設(shè)定在/var/www/
1、在/var/www/下新建兩個(gè)目錄
/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; #主要是加入此行,如有則忽略 }
3、在/etc/nginx/conf.d下新建兩個(gè)conf文件,
/etc/nginx/conf.d/ushark.net.conf /etc/nginx/conf.d/ushark.wang.conf
4、復(fù)制如下配置信息到兩個(gè)文件中,只要修改紅色部分內(nèi)容 !!! server_name與root保持一致即目錄和域名一一對(duì)應(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 的方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
相關(guān)文章
一文教會(huì)你從Windows中完全刪除node.js
作為新手nodejs卸載后安裝就總出錯(cuò),下面這篇文章主要給大家介紹了關(guān)于如何從Windows中完全刪除node.js的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08詳解如何模擬實(shí)現(xiàn)node中的Events模塊(通俗易懂版)
這篇文章主要介紹了如何模擬實(shí)現(xiàn)node中的Events模塊(通俗易懂版),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04Node.js全局可用變量、函數(shù)和對(duì)象示例詳解
JavaScript中有一個(gè)特殊的對(duì)象,稱為全局對(duì)象(Global Object),它及其所有屬性都可以在程序的任何地方訪問(wèn),即全局變量,下面這篇文章主要給大家介紹了關(guān)于Node.js全局可用變量、函數(shù)和對(duì)象的相關(guān)資料,需要的朋友可以參考下2023-03-03Node連接MySQL并封裝其增刪改查的實(shí)現(xiàn)代碼
本文主要介紹了Node連接MySQL并封裝其增刪改查的實(shí)現(xiàn)代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12Nodejs使用express 編寫接口的實(shí)現(xiàn)
express是一個(gè)第三方模塊,支持豐富的api,本文主要介紹了Nodejs使用express 編寫接口的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-06-06node.js中的fs.chmodSync方法使用說(shuō)明
這篇文章主要介紹了node.js中的fs.chmodSync方法使用說(shuō)明,本文介紹了fs.chmodSync方法說(shuō)明、語(yǔ)法、接收參數(shù)、使用實(shí)例和實(shí)現(xiàn)源碼,需要的朋友可以參考下2014-12-12使用Raygun對(duì)Node.js應(yīng)用進(jìn)行錯(cuò)誤處理的方法
這篇文章主要介紹了使用Raygun對(duì)Node.js應(yīng)用進(jìn)行錯(cuò)誤處理的方法,Node.js是一款用于服務(wù)器端的JavaScript框架,需要的朋友可以參考下2015-06-06