location / { root html; index index.html index.htm; } } 4.配置cert.pem文件 cd /etc/pki/tls/certs/ make cert.pem ....... Country Name (2 letter code) [XX]:ch #國家名稱(2字母代碼) State or Province Name (full name) []:shannxi #州或省的名稱(全稱) Locality Name (eg, city) [Default City]:xi'an #地區名稱(如,市)[默認城市] Organization Name (eg, company) [Default Company Ltd]:123.org #默認有限公司組織的名稱(例如,公司)] Organizational Unit Name (eg, section) []:linux #組織單位的名稱(例如,一節) Common Name (eg, your name or your server's hostname) []:salim #通用名稱(例如,您的姓名或您的伺服器的主機名 Email Address []:root@localhost #電子郵件地址
5. 調試 nginx -t #查看語法 the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok configuration file /usr/local/nginx/conf/nginx.conf test is successful
6. 啟動 nginx nginx -s reload 刷新
訪問:http://127.0.0.1 Welcome to nginx!
這樣您就能看到nginx畫面了
安裝完畢nginx后,我將會會大家進行一些擴展,其中最有用的是虛擬用戶,和負載均衡。
一 虛擬用戶
1.創建虛擬主機: mkdir /usr/local/nginx/conf/virtualhost cd /usr/local/nginx/conf/virtualhost mkdir www.luoning.com mkdir www.luoning.cn 2.新建默認頁: cd www.luoning.com echo luoning.com > index.html cd www.luoning.cn echo www.luoning.cn> index.html 3.添加解析: vi /etc/hosts 192.168.0.27 www.luoning.com 192.168.0.27 www.luoning.cn 4.用ping檢測虛擬主機查看路徑 5.vi /usr/local/nginx/conf/nginx.conf
添加
server { listen 80; server_name www.luoning.cn; location / { root virtualhost/www.luoning.cn; index index.html index.htm; } }
server { listen 80; server_name www.luoning.com; location / { root virtualhost/www.luoning.com; index index.html index.htm; } }
nginx -t 調試查看語法
訪問: http://www.luoning.com http://www.luoning.cn
二 .負載均衡
vi /usr/local/nginx/conf/nginx.conf ...... upstream hello { server 192.168.0.1:80; server 192.168.0.2:80; }