目录
一、概述
二、yum安装/rpm安装:nginx
三、nginx 配置文件修改
四、配置文件
基于不同端口号
基于不同IP地址
基于不同域名
一、概述 功能:web中间件、反向代理、缓存 特点:并发连接数高,单台主机并发可到达50000 只能解析静态页面 工作模型:epoll 监听端口号:80
二、yum安装/rpm安装:nginx
[root@localhost ~] ping www.baidu.com #确保能ping通外网
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
准备中... ################################# [100%]
正在升级/安装...
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
主机头配置文件:/etc/nginx/con.f/default.conf
服务器启动:systemctl start nginx 停止:systemctl stop nginx
五、虚拟主机头
基于不同端口号
1.修改conf.d中主机头配置文件
[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个虚拟主机头
[root@localhost conf.d] cp default.conf skl2.conf
[root@localhost conf.d] rm -rf default.conf #删除原本虚拟主机头
[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 第二个文件填写第二个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中的访问日志配置项
[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.创建访问目录并写入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 #写入自己的首页内容
[root@localhost skl1] vim ../
50x.html skl1/ skl2/
[root@localhost skl1] vim ../skl2/index.html
4.重启服务器
[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;
文章来源:https://www.toymoban.com/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 #添加域名声明
~
~
文章来源地址https://www.toymoban.com/news/detail-733090.html
到了这里,关于Linux下nginx配置、使用的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!