Ngix是web服務(wù)器蚂维,跟apache一樣戳粒,它可以做動態(tài)請求轉(zhuǎn)發(fā)、web端負(fù)載均衡虫啥、反向代理等等
1蔚约、關(guān)閉防火墻和selinux
2、安裝依賴軟件
yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel
3孝鹊、tar -zxvf nginx-1.11.5.tar.gz
4炊琉、創(chuàng)建www用戶,不允許以www用戶登錄系統(tǒng)
useradd www -s /sbin/nologin
5又活、./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
6苔咪、make && make install
7、cp nginx /etc/init.d/
8柳骄、開啟服務(wù)
service nginx start
9团赏、設(shè)置開機(jī)啟動
chkconfig nginx on
chkconfig --list 查看是否開機(jī)啟動
10、查看網(wǎng)絡(luò)和端口使用情況
netstat -lnp | grep nginx
nginx默認(rèn)監(jiān)聽的端口為80端口
虛擬主機(jī)配置步驟
(1)修改nginx配置文件
vi /usr/local/nginx/conf/nginx.conf
在第116行加一行代碼
include vhost/*.conf;
(2)新建一個vhost文件夾
mkdir /usr/local/nginx/conf/vhost
(3)來到vhost下耐薯,新建一個虛擬主機(jī)配置文件
vi /usr/local/nginx/conf/vhost/www.lala.com.conf
server
{
server_name www.lala.com;
root html/lala;
index index.html;
}
[說明]:
server_name : 域名
root : 網(wǎng)站的根目錄
index : 網(wǎng)站的默認(rèn)首頁
(4)新建虛擬主機(jī)根目錄
mkdir /usr/local/nginx/html/lala
vi /usr/local/nginx/html/lala/index.html
service nginx restart 重啟服務(wù)
(5)編輯本機(jī)的hosts文件
C:\Windows\System32\drivers\etc\hosts
10.9.151.154 www.lala.com