假設你想在Linux Nginx中用不同的域名訪問不同的目錄,這時就要配置多個vhost,具體配置如下,假設網站根目錄設定在/var/www/
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; #主要是加入此行,如有則忽略}
3、在/etc/nginx/conf.d下新建兩個conf文件,
/etc/nginx/conf.d/ushark.net.conf/etc/nginx/conf.d/ushark.wang.conf
4、復制如下配置信息到兩個文件中,只要修改紅色部分內容 !!! server_name與root保持一致即目錄和域名一一對應 !!!
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; #}}
5、重啟Nginx
systemctl restart nginx
6、 編輯/etc/hosts !!! 核心步驟 !!!
[root@bogon ~]# vi 127.0.0.1 localhost.localdomain localhost::1 localhost6.localdomain6 localhost6127.0.0.1 www.ushark.net127.0.0.1 www.ushark.wang
7、設置成功
本文由 貴州做網站公司 整理發布,部分圖文來源于互聯網,如有侵權,請聯系我們刪除,謝謝!
網絡推廣與網站優化公司(網絡優化與推廣專家)作為數字營銷領域的核心服務提供方,其價值在于通過技術手段與策略規劃幫助企業提升線上曝光度、用戶轉化率及品牌影響力。這...
在當今數字化時代,公司網站已成為企業展示形象、傳遞信息和開展業務的重要平臺。然而,對于許多公司來說,網站建設的價格是一個關鍵考量因素。本文將圍繞“公司網站建設價...
在當今的數字化時代,企業網站已成為企業展示形象、吸引客戶和開展業務的重要平臺。然而,對于許多中小企業來說,高昂的網站建設費用可能會成為其發展的瓶頸。幸運的是,隨...
播客是干什么用的 播客是什么意思? 蘋果上的播客是干什么用的? 播客為iPod broadcasting,一種數字廣播技術。在出現初期,借助一iPodder該軟件與一些便攜式播放器相結合。Podcasting錄制的是網絡廣播或類似的網絡聲音節目,網民可以下載自己的網絡廣播節目iPod、MP3.在播放器或其他便攜式數字聲音播放器中隨身聽。不用坐在電腦前,也不用實時聽,隨時隨地享受自由。也可以自...
writer和writing的區別?write的進行時態是:writing。根據變化規律,以無聲字母E結尾的動詞刪去E,加上ing。分析:write的結尾是e。當你改變現在進行時,你需要去掉e的結尾。同樣,make to making和use changes to using。我正在寫一本關于我童年的書。是關于一個男孩和他祖父之間的友誼。請問write的進行時態到底是writing還是writti...
ps4發售上市時間?國行PS4主機于2014年12月12日零點開啟國內預售,2015年1月11日正式發售。Ps4多少年前出的?八年前,2014年2月22日是PS4在日本發售的日子,而國行的PS4是2015年3月20日發售的。到目前為止,PS4銷量已經超過1.169億臺,足以稱得上流行硬件。PlayStation4是索尼銷售的一款固定家用游戲機,被親切地稱為 "PS4 "被游戲玩家。如序列號所示,...