Nginx 筆記與總結(3)配置虛擬主機

Nginx 重啟的另外一種方式,相當于 kill -HUP `cat /usr/local/nginx/logs/nginx.pid`:

 /usr/local/nginx/sbin/nginx  -s reload

?

停止 Nginx 的另外一種方式:

 /usr/local/nginx/sbin/nginx  -s stop

?

重讀日志文件的另一種方式,相當于 kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`:

 /usr/local/nginx/sbin/nginx  -s reopen

?

測試配置文件是否正確:

/usr/local/nginx/sbin/nginx  -t

如果配置正確,則會提示 successful:

  

?

?

?

虛擬主機的管理

vim /usr/local/nginx/conf/nginx.conf

?

全局區

worker_processes ?1 表示有 1 個工作的子進程,可以進行修改,但是過大沒有意義,因為需要占用更多的 CPU 資源,一般設置為 CPU 數 * 核數

?

events 區

一般配置 Nginx 進程與連接的特性。worker_connections ?1024 表示 1 個子進程(worker)最多允許 1024 個連接。

?

http 段

  1 http {
  2     include       mime.types;
  3     default_type  application/octet-stream;
  4 
  5     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  6     #                  '$status $body_bytes_sent "$http_referer" '
  7     #                  '"$http_user_agent" "$http_x_forwarded_for"';
  8 
  9     #access_log  logs/access.log  main;
 10 
 11     sendfile        on;
 12     #tcp_nopush     on;
 13 
 14     #keepalive_timeout  0;
 15     keepalive_timeout  65;
 16 
 17     #gzip  on;
 18 
 19     server {
 20         listen       80;
 21         server_name  localhost;
 22 
 23         #charset koi8-r;
 24 
 25         #access_log  logs/host.access.log  main;
 26 
 27         location / {
 28             root   html;
 29             index  index.html index.htm;
 30         }
 31 
 32         #error_page  404              /404.html;
 33 
 34         # redirect server error pages to the static page /50x.html
 35         #
 36         error_page   500 502 503 504  /50x.html;
 37         location = /50x.html {
 38             root   html;
 39         }
 40 
 41         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
 42         #
 43         #location ~ \.php$ {
 44         #    proxy_pass   http://127.0.0.1;
 45         #}
 46 
 47         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 48         #
 49         #location ~ \.php$ {
 50         #    root           html;
 51         #    fastcgi_pass   127.0.0.1:9000;
 52         #    fastcgi_index  index.php;
 53         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 54         #    include        fastcgi_params;
 55         #}
 56 
 57         # deny access to .htaccess files, if Apache's document root
 58         # concurs with nginx's one
 59         #
 60         #location ~ /\.ht {
 61         #    deny  all;
 62         #}
 63     }
 64 
 65 
 66     # another virtual host using mix of IP-, name-, and port-based configuration
 67     #
 68     #server {
 69     #    listen       8000;
 70     #    listen       somename:8080;
 71     #    server_name  somename  alias  another.alias;
 72 
 73     #    location / {
 74     #        root   html;
 75     #        index  index.html index.htm;
 76     #    }
 77     #}
 78 
 79 
 80     # HTTPS server
 81     #
 82     #server {
 83     #    listen       443 ssl;
 84     #    server_name  localhost;
 85 
 86     #    ssl_certificate      cert.pem;
 87     #    ssl_certificate_key  cert.key;
 88 
 89     #    ssl_session_cache    shared:SSL:1m;
 90     #    ssl_session_timeout  5m;
 91 
 92     #    ssl_ciphers  HIGH:!aNULL:!MD5;
 93     #    ssl_prefer_server_ciphers  on;
 94 
 95     #    location / {
 96     #        root   html;
 97     #        index  index.html index.htm;
 98     #    }
 99     #}
100 
101 }
View Code

配置 http 服務器的主要的段。

?

http 段中的 server 段

    server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  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   html;}# 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$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}

server 就是虛擬主機。

?

?

【例1】基于域名的虛擬主機

添加 server 段:

    server{listen 80;server_name dee.com;location /{root dee.com;index index.html;}}

保存退出;

location 可以使用絕對路徑,也可以使用相對路徑,相對路徑是相對于 nginx 的根目錄:/usr/local/nginx

?

在 /usr/local/nginx 目錄下創建目錄 dee.com,在其下創建 index.html:

[root@localhost ~]# cd /usr/local/nginx/
[root@localhost nginx]# mkdir dee.com
[root@localhost nginx]# vim dee.com/index.html

index.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>dee.com</title>
<body>
Welcome to dee.com
</body>
</head>
</html>

?

重新讀取配置文件:

/usr/local/nginx/sbin/nginx  -s reload

?

配置 hosts:

192.168.254.100  dee.com

?

訪問 dee.com:

?

?

【例2】基于 ip 的虛擬主機

?

?編輯配置文件:

vim /usr/local/nginx/conf/nginx.conf

添加 server 段:

    server{listen 80;server_name 192.168.254.100;location /{root ip;index index.html;}}

?

在 /usr/local/nginx 目錄下新建 ip 目錄:

[root@localhost nginx]# mkdir ip
[root@localhost nginx]# vim ip/index.html

?

?index.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>dee.com</title>
<body>
ip test
</body>
</head>
</html>

?

訪問 http://192.168.254.100/

?

  

?

【例3】基于端口的虛擬主機

?編輯配置文件(vim 查看行號 :set nu):

vim /usr/local/nginx/conf/nginx.conf

添加 server 段:

    server{listen 2022;server_name dee.com;location /{root /var/www;index index.html;}} 

這時配置 location 使用絕對路徑;  

?

在 /var 下新建 www 目錄,在其下新建 index.html 文件:

[root@localhost nginx]# mkdir /var/www
[root@localhost nginx]# vim /var/www/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>dee.com</title>
<body>
Welcome to dee.com's admin panel
</body>
</head>
</html>

?

重新讀取配置文件:

/usr/local/nginx/sbin/nginx  -s reload

?

訪問 http://dee.com:2022/

?

或者訪問 http://192.168.254.100:2022/

  

?

?

附:如果需要啟用目錄瀏覽,只需要在 Server 段中加入 autoindex on;

轉載于:https://www.cnblogs.com/dee0912/p/4671764.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/397781.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/397781.shtml
英文地址,請注明出處:http://en.pswp.cn/news/397781.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

計算機如何查找目標,如何使用命令行查找計算機地理位置? | MOS86

有多種方法可以從IP地址中了解計算機的位置&#xff0c;但如果您決定使用命令行查找信息&#xff0c;那么您如何處理&#xff1f;今天今天的問題Screenshot由Paul Fenwick(Flickr)提供。問題SuperUser閱讀器AlikElzin-kilaka想知道如何找到一臺電腦首先&#xff0c;AlikElzin-k…

Nmap命令的常用實例

一、Nmap簡介 nmap是一個網絡連接端掃描軟件&#xff0c;用來掃描網上電腦開放的網絡連接端。確定哪些服務運行在哪些連接端&#xff0c;并且推斷計算機運行哪個操作系統&#xff08;這是亦稱 fingerprinting&#xff09;。它是網絡管理員必用的軟件之一&#xff0c;以及用以評…

mysql sqlexception_c-很奇怪-mysql的sql :: SQLException未被其類型捕...

我正在使用帶有此(稍微簡化)代碼的mysql c連接器.try{statement->setString(1, word);statement->executeUpdate();}catch( sql::SQLException& e ){// I dont get herereturn sqlerrno_to_error_code( e.getErrorCode() );}catch( std::exception& e ){// I do …

Linux Kernel系列 - 黃牛X內核代碼凝視

Hanks.Wang - 專注于操作系統與移動安全研究。Linux-Kernel/SELinux/SEAndroid/TrustZone/Encription/MDM Mail - byhankswanggmail.com 牛X的內核代碼凝視 大牛的代碼質量高穩定性好&#xff0c;并且邏輯清晰易讀性比較強&#xff0c;今天看到Linux Kernel紅黑樹的代碼時&a…

電子商務計算機網絡安全技術教案,網絡安全技術教案.pdf

名師精編 優秀教案《網絡安全技術》教案2011-2012 第 2 學期適用班級&#xff1a; 2010 級計算機網絡技術專業編寫&#xff1a;徐英武名師精編 優秀教案第 1~2 課時周次 &#xff11; 日期 2012 年 02 月 14 日 授課班級 2010 級計算機網絡技術課題 網絡安全概述 課 型 理論課教…

技術文章匯總

點擊以下鏈接&#xff0c;可以查看相關技術文章&#xff1a;包括APP軟件開發、手機軟件開發、嵌入式開發、Java和C/C編程&#xff0c;同時涉及原型設計、效果圖設計、切圖、網絡、多媒體、加密、字符編碼、通信原理、測試和項目管理等各方面的知識。APP開發實戰手機開發實戰技術…

咋樣查mysql的url_eclipse用jdbc連接mysql數據庫時,url是填什么?怎樣找出地址?

展開全部 jdbc連接mysql數據62616964757a686964616fe78988e69d8331333337623535庫的url為: jdbc:mysql://主機名或IP抵制:端口號/數據庫名?useUnicode=true&characterEncoding=UTF-8 jdbc連接其他數據庫的連接字符串寫法為:1、Oracle8/8i/9i數據庫(thin模式) Class.for…

HP服務器ile進系統,HP GEN10服務器UEFI安裝Windows Sverver 2012 R2教程

1.操作系統&#xff1a;Windows Server 2012 R2 VL with Update (x64) – DVD (Chinese-Simplified)&#xff0c;MSDN下載地址&#xff1a;ed2k://|file|cn_windows_server_2012_r2_vl_with_update_x64_dvd_6052729.iso|5545527296|BD499EBCABF406AB82293DD8A5803493|/2.鏡像寫…

[程序設計語言] 堆和棧的全面總結

操作系統堆棧&#xff1a; 分配由編譯器自己主動和自己主動釋放。對應于堆棧的函數。參數存儲功能值、函數調用結束后完成值和局部變量的函數體內。段內存空間。其操作和組織方式與數據結構中的棧十分相似。棧是為了運行線程留出的內存空間。當調用函數時創建棧。當函數運行完畢…

py文件的操作

文件操作基本流程。 計算機系統分為&#xff1a;計算機硬件&#xff0c;操作系統&#xff0c;應用程序三部分。 我們用python或其他語言編寫的應用程序若想要把數據永久保存下來&#xff0c;必須要保存于硬盤中&#xff0c;這就涉及到應用程序要操作硬件&#xff0c;眾所周知&a…

CentOS系統啟動流程你懂否

一、Linux內核的組成相關概念&#xff1a;Linux系統的組成部分&#xff1a;內核根文件系統內核&#xff1a;進程管理、內存管理、網絡協議棧、文件系統、驅動程序。IPC(Inter-Process Communication進程間通信):就是指多個進程之間相互通信&#xff0c;交換信息的方法。Linux I…

怎樣用css設置圖片下的投影,css – 做這種投影的最佳方法是什么?

如果您更喜歡使用CSS來創建該類型的陰影,則可以將CSS3用作seen here!CSS/* Lifted corners */.lifted {-moz-border-radius:4px;border-radius:4px;}.lifted:before,.lifted:after {bottom:15px;left:10px;width:50%;height:20%;max-width:300px;-webkit-Box-shadow:0 15px 10p…

mysql 排版 指令_Mysql語句排版

SQL 高效排版指北統一 SQL 排版的相關用法&#xff0c;極大提高編寫和維護 SQL 的效率。注: column 選取的字段&#xff1b;table 選取的表名語句結構錯誤SELECT column1 FROM table1 ORDER BY column1正確SELECTcolumn1FROMtable1ORDER BYcolumn1解析SQL 語句在內部執行時會…

Linux命令學習手冊-tr命令 2015-07-26 20:35 9人閱讀 評論(0) 收藏...

tr [OPTION]... SET1 [SET2] [功能] 轉換或者刪除字符。 [描述] tr指令從標準輸入設備讀取數據&#xff0c;經過字符串轉譯后&#xff0c;輸出到標準輸出設備。 通過使用 tr&#xff0c;您可以非常容易地實現 sed 的許多最基本功能。您可以將 tr 看作為 sed 的&#xff08…

css商品,商品標簽例子——CSS3 transform 屬性

積累很重要。從此開始記錄前端生涯的點滴....div{width:150px;height:30px;background-color:#f83944;/* Rotate div */transform:rotate(-40deg);-ms-transform:rotate(-40deg); /* Internet Explorer */-moz-transform:rotate(-40deg); /* Firefox */-webkit-transform:rotat…

The literal of int xxxxx is out of range

有時候我們定義了long型的變量&#xff0c;當我們給該變量賦值過長的整數時&#xff0c;系統依然會提示長度超過范圍&#xff0c;解決辦法如下&#xff1a; long timeShow 1437565243495L; 我們需要在整形變量的后面加上“L”&#xff0c;便可以避免系統報錯。轉載于:https://…

debian 訪問 windows 共享_【續】windows環境redis未授權利用方式梳理

01Redis未授權產生原因1.redis綁定在0.0.0.0:6379默認端口&#xff0c;直接暴露在公網&#xff0c;無防火墻進行來源信任防護。2.沒有設置密碼認證&#xff0c;可以免密遠程登錄redis服務02漏洞危害1.信息泄露&#xff0c;攻擊者可以惡意執行flushall清空數據2.可以通過eval執行…

HTML比較常用的標簽

1.全局架構標簽&#xff1a;<html><head><title>標題</title><meta charset"utf-8"></head><body>正文部分</body></html><!--注釋部分-->2.body標簽的屬性bgcolor&#xff1a;背景色text:整個網頁的顏…

sae項目服務器,基于SAE的游戲服務器: Server on SAE for RGSS Games 部署在SAE上的簡易游戲服務器,為用 RMXP/VX/VA 開發的游戲提供網絡服務...

本項目已經關閉服務端已經關閉并且不再重啟&#xff0c;后續請訪問 RGSOS on Gitlab基于SAE的游戲服務器重寫服務端邏輯中……暫時無法正常提供服務功能數據庫封裝封裝了 SAE 上的 Memcached&#xff0c;KVDB 和 Storage 到 SAE_IO 類&#xff0c;并引申到兩個子類&#xff1a;…

1090 Highest Price in Supply Chain (25)

A supply chain is a network of retailers&#xff08;零售商&#xff09;, distributors&#xff08;經銷商&#xff09;, and suppliers&#xff08;供應商&#xff09;-- everyone involved in moving a product from supplier to customer. Starting from one root suppli…