0
点赞
收藏
分享

微信扫一扫

RHCE作业(一)

琛彤麻麻 2024-11-02 阅读 27
linux

安装nginx实现多ip访问多网站

[root@localhost yanyan]# systemctl stop firewalld  #关闭防火墙
[root@localhost yanyan]# sudo setenforce 0  #关闭selinux
[root@localhost yanyan]# sudo mount /dev/sr0 /mnt
mount: /mnt: WARNING: source write-protected, mounted read-only.  #挂载本地目录
[root@localhost yanyan]# sudo vim /etc/yum.repos.d/nginx.repo  #建立本地源
[root@localhost yanyan]# cat /etc/yum.repos.d/nginx.repo

[root@localhost yanyan]# sudo dnf install nginx -yUpdating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

BaseOS            266 MB/s | 2.0 MB     00:00    
AppStream         293 MB/s | 6.5 MB     00:00    
Dependencies resolved.
==================================================
 Package
       Arch   Version             Repo       Size
==================================================
Installing:
 nginx x86_64 1:1.20.1-14.el9_2.1 AppStream  40 k
Installing dependencies:
 nginx-core
       x86_64 1:1.20.1-14.el9_2.1 AppStream 574 k
 nginx-filesystem
       noarch 1:1.20.1-14.el9_2.1 AppStream  11 k
 redhat-logos-httpd
       noarch 90.4-2.el9          AppStream  18 k

Transaction Summary
==================================================
Install  4 Packages

Total size: 643 k
Installed size: 1.8 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                          1/1 
  Running scriptlet: nginx-filesystem-1:1.2   1/4 
  Installing       : nginx-filesystem-1:1.2   1/4 
  Installing       : nginx-core-1:1.20.1-14   2/4 
  Installing       : redhat-logos-httpd-90.   3/4 
  Installing       : nginx-1:1.20.1-14.el9_   4/4 
  Running scriptlet: nginx-1:1.20.1-14.el9_   4/4 
  Verifying        : nginx-1:1.20.1-14.el9_   1/4 
  Verifying        : nginx-core-1:1.20.1-14   2/4 
  Verifying        : nginx-filesystem-1:1.2   3/4 
  Verifying        : redhat-logos-httpd-90.   4/4 
Installed products updated.

Installed:
  nginx-1:1.20.1-14.el9_2.1.x86_64                
  nginx-core-1:1.20.1-14.el9_2.1.x86_64           
  nginx-filesystem-1:1.20.1-14.el9_2.1.noarch     
  redhat-logos-httpd-90.4-2.el9.noarch            

Complete!
[root@localhost yanyan]# systemctl start nginx  #开启nginx
[root@localhost yanyan]# systemctl start nginx
[root@localhost yanyan]# netstat -tunlp  #检查nginx是否开启
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1060/cupsd          
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      3137/sshd: yanyan@p 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1062/sshd: /usr/sbi 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      34061/nginx: master 
tcp6       0      0 ::1:6010                :::*                    LISTEN      3137/sshd: yanyan@p 
tcp6       0      0 ::1:631                 :::*                    LISTEN      1060/cupsd          
tcp6       0      0 :::22                   :::*                    LISTEN      1062/sshd: /usr/sbi 
tcp6       0      0 :::80                   :::*                    LISTEN      34061/nginx: master 
udp        0      0 0.0.0.0:43776           0.0.0.0:*                           863/avahi-daemon: r 
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           863/avahi-daemon: r 
udp        0      0 127.0.0.1:323           0.0.0.0:*                           898/chronyd         
udp6       0      0 :::37943                :::*                                863/avahi-daemon: r 
udp6       0      0 :::5353                 :::*                                863/avahi-daemon: r 
udp6       0      0 ::1:323                 :::*                                898/chronyd         
[root@localhost yanyan]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1060/cupsd          
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      3137/sshd: yanyan@p 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1062/sshd: /usr/sbi 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      34061/nginx: master 
tcp6       0      0 ::1:6010                :::*                    LISTEN      3137/sshd: yanyan@p 
tcp6       0      0 ::1:631                 :::*                    LISTEN      1060/cupsd          
tcp6       0      0 :::22                   :::*                    LISTEN      1062/sshd: /usr/sbi 
tcp6       0      0 :::80                   :::*                    LISTEN      34061/nginx: master 
udp        0      0 0.0.0.0:43776           0.0.0.0:*                           863/avahi-daemon: r 
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           863/avahi-daemon: r 
udp        0      0 127.0.0.1:323           0.0.0.0:*                           898/chronyd         
udp6       0      0 :::37943                :::*                                863/avahi-daemon: r 
udp6       0      0 :::5353                 :::*                                863/avahi-daemon: r 
udp6       0      0 ::1:323                 :::*                                898/chronyd  
[root@localhost yanyan]# nmtui  #修改静态IP地址

[root@localhost yanyan]# nmcli connection up ens160  #启动网卡
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)

[root@localhost yanyan]# vim /etc/nginx/conf.d/test_ip.conf  #自定义nginx配置文件通过多地址区分多网站

[root@localhost yanyan]# cat /etc/nginx/conf.d/test_ip.conf
server {
	listen 192.168.142.129:80;
	root /www/ip/129;
	location /{ #配置/==/www/ip/100下的资源文件
	}
}
server {
	listen 192.168.142.128:80;
	root /www/ip/128;
	location /{ #配置/==/www/ip/100下的资源文件
		index index.html;
	}
}
[root@localhost yanyan]# mkdir /www/ip/{129,128} -pv
mkdir: created directory '/www'
mkdir: created directory '/www/ip'
mkdir: created directory '/www/ip/129'
mkdir: created directory '/www/ip/128'
[root@localhost yanyan]# echo this is 129 > /www/ip/129/index.html
[root@localhost yanyan]# echo this is 128 > /www/ip/128/index.html
[root@localhost yanyan]# systemctl restart nginx
[root@localhost yanyan]# curl 192.168.142.128
this is 128
[root@localhost yanyan]# curl 192.168.142.129
this is 129

 

举报

相关推荐

RHCE作业

RHCE 作业三

RHCE---作业2

RHCE~

第一次rhce实验

rhce day1

0 条评论