[root@openEuler ~]# wget https://repo.huaweicloud.com/nginx/nginx-1.9.9.tar.gz
解压与编译
tar -zxvf nginx-1.9.9.tar.gz cd nginx-1.9.9 ./configure make make install
进入安装目录
[root@openEuler nginx-1.9.9]# cd /usr/local/nginx/sbin/
启动nginx
[root@openEuler sbin]# nginx
测试是否安装成功,访问网页
[root@openEuler sbin]# curl http://127.0.0.1Welcome to nginx! html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.Thank you for using nginx.
配置主机防火墙服务,要求计算机重启后仍能通过网页访问nginx首页.
此时无法在浏览器中通过IP地址访问,需要配置主机防火墙服务
查询防火墙状态,是在运行中
[root@openEuler sbin]# service firewalld status
Redirecting to /bin/systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-10-12 11:20:02 CST; 5h 32min ago
Docs: man:firewalld(1)
Main PID: 773 (firewalld)
Tasks: 2
Memory: 31.5M
CGroup: /system.slice/firewalld.service
└─773 /usr/bin/python3 /usr/sbin/firewalld --nofork --nopid
Oct 12 11:20:01 openEuler systemd[1]: Starting firewalld - dynamic firewall daemon...
Oct 12 11:20:02 openEuler systemd[1]: Started firewalld - dynamic firewall daemon.
查询防火墙规则,发现并没有开放80端口
[root@openEuler sbin]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: enp0s3 sources: services: dhcpv6-client mdns ssh ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [root@openEuler sbin]# firewall-cmd --query-port=80/tcp no
添加80端口,重启防火墙,再查询防火墙规则,可以看到80商品已经开放
[root@openEuler sbin]# firewall-cmd --permanent --add-port=80/tcp success [root@openEuler sbin]# service firewalld restart Redirecting to /bin/systemctl restart firewalld.service [root@openEuler sbin]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: enp0s3 sources: services: dhcpv6-client mdns ssh ports: 80/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [root@openEuler sbin]# firewall-cmd --query-port=80/tcp yes
浏览器中就可以正常访问nginx



