目錄
一、概述? ?
二、yum安裝/rpm安裝:nginx
三、nginx 配置文件修改
四、配置文件
基于不同端口號(hào)
?基于不同IP地址
基于不同域名
一、概述 ?? ?功能:web中間件、反向代理、緩存 ?? ?特點(diǎn):并發(fā)連接數(shù)高,單臺(tái)主機(jī)并發(fā)可到達(dá)50000 ? ? ? ? ? ? ? ?只能解析靜態(tài)頁(yè)面 ?? ?工作模型:epoll ?? ?監(jiān)聽端口號(hào):80
二、yum安裝/rpm安裝:nginx
[root@localhost ~] ping www.baidu.com #確保能ping通外網(wǎng)
PING www.baidu.com (124.237.176.4) 56(84) bytes of data.
64 bytes from 124.237.176.4 (124.237.176.4): icmp_seq=1 ttl=128 time=15.9 ms
64 bytes from 124.237.176.4 (124.237.176.4): icmp_seq=2 ttl=128 time=16.4 ms
^C
--- www.baidu.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 15.926/16.201/16.476/0.275 ms
[root@localhost ~] rpm -ivh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.14.2-1.el7_4.ngx.x86_64.rpm
獲取http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.14.2-1.el7_4.ngx.x86_64.rpm
警告:/var/tmp/rpm-tmp.riNLEC: 頭V4 RSA/SHA1 Signature, 密鑰 ID 7bd9bf62: NOKEY
準(zhǔn)備中... ################################# [100%]
正在升級(jí)/安裝...
1:nginx-1:1.14.2-1.el7_4.ngx ################################# [100%]
三、nginx 配置文件修改
[root@localhost ~] cd /usr/share/nginx/html/
[root@localhost html] ll
總用量 8
-rw-r--r--. 1 root root 537 12月 4 2018 50x.html
-rw-r--r--. 1 root root 612 12月 4 2018 index.html
四、配置文件
路徑:/etc/nginx
主配置文件:/etc/nginx/nginx.conf
主機(jī)頭配置文件:/etc/nginx/con.f/default.conf
服務(wù)器啟動(dòng):systemctl start nginx ?停止:systemctl stop nginx
五、虛擬主機(jī)頭
基于不同端口號(hào)
1.修改conf.d中主機(jī)頭配置文件
[root@localhost nginx] cd conf.d/
[root@localhost conf.d] ll
總用量 4
-rw-r--r--. 1 root root 1093 12月 4 2018 default.conf
[root@localhost conf.d] cp default.conf skl1.conf #拷貝2個(gè)虛擬主機(jī)頭
[root@localhost conf.d] cp default.conf skl2.conf
[root@localhost conf.d] rm -rf default.conf #刪除原本虛擬主機(jī)頭
[root@localhost conf.d] vim skl1.conf
[root@localhost conf.d] vim skl2.conf #同理
server {
listen 80;
listen 192.168.9.143:80; #加入你的dhcp獲取的IP 第二個(gè)文件填寫第二個(gè)IP
server_name localhost;
#charset koi8-r;
access_log /var/log/nginx/143.access.log main; #取消注釋
location / {
root /usr/share/nginx/html/skl1; #改成你的index文件路徑
index index.html index.htm;
}
#error_page 404 /404.html;
2.注釋nginx.conf中的訪問(wèn)日志配置項(xiàng)
[root@localhost nginx] vim nginx.conf
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main; # 取消此行注釋
3.創(chuàng)建訪問(wèn)目錄并寫入index.html文件
[root@localhost ~] cd /usr/share/nginx/html/
[root@localhost html] ll
總用量 8
-rw-r--r--. 1 root root 537 12月 4 2018 50x.html
-rw-r--r--. 1 root root 612 12月 4 2018 index.html
[root@localhost html] mkdir skl1
[root@localhost html] mkdir skl2
[root@localhost html] cp index.html skl1/
[root@localhost html] cp index.html skl2/
[root@localhost html] rm -rf index.html
[root@localhost ~] cd /usr/share/nginx/html/skl1
[root@localhost skl1] vim index.html #寫入自己的首頁(yè)內(nèi)容
[root@localhost skl1] vim ../
50x.html skl1/ skl2/
[root@localhost skl1] vim ../skl2/index.html
4.重啟服務(wù)器
[root@localhost conf.d] systemctl start nginx
[root@localhost conf.d]
?基于不同IP地址
server {
listen 80;
listen 192.168.159.142:8081; #修改
server_name localhost;
#charset koi8-r;
access_log /var/log/nginx/8081.access.log main; #修改
location / {
root /usr/share/nginx/html/skl1;
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-733090.html
基于不同域名
[root@localhost conf.d]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.159.142 dns.skl.com #添加域名聲明
192.168.159.145 www.skl.com #添加域名聲明
~
~
?
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-733090.html
到了這里,關(guān)于Linux下nginx配置、使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!