赞
踩
linux上nginx的安装方法:
1、cd /usr/local/src 进入此目录后执行wget http://nginx.org/download/nginx-1.14.0.tar.gz 下载nginx压缩包
(1.1)这里如果使用的是纯净版centos可能是不自带wget的,所以需要 yum install wget ,这时候如果报错就是网络设置原因,保证网络桥接的模式下,前往/etc/resolv.conf 新增nameserver 8.8.8.8 可使用echo “nameserver 8.8.8.8”>> /etc/resolv.conf。
(1.2)下载好后执行tar --zxvf nginx-1.14.0.tar.gz 解压nginx
2、进入解压后文件执行./configure --prefix=/usr/local/nginx 改变目录地址,也可以不改。
(2.1)如果中途报缺少什么包之类的错误,只需执行yum install 相应的包名,nginx依赖有
yum install gcc-c++ nginx为c++编写
yum install prec prec-devel 正则
yum install zlib zlib-devel
(2.2)成功后执行编译make && make install
3、进入 /usr/local/nginx 执行ls查看是否存在 conf,log,html,sbin四个目录,其中的sbin中存在一个二进制文件nginx直接执行就可开启nginx ,然后可以使用ps -ef|grep nginx 查看状态
以上三步就是nginx的安装方法
linux上nginx的开启及关闭:
1、以下几个命令常用
netstat -ant 看端口pkill -9 服务
nginx从容停止命令,等所有请求结束后关闭服务
ps -ef |grep nginx
kill -QUIT nginx主进程号
nginx 快速停止命令,立刻关闭nginx进程
ps -ef |grep nginx
kill -TERM nginx主进程号
如果以上命令不管用,可以强制停止
kill -9 nginx主进程号
linux上本地访问虚拟机的nginx页面:
本虚拟机装有centos7
安装好centos7.3后,登陆虚拟机,在命令框输入“ifconfig”会发现一个问题,网卡不在是“eth0”,而是“ens33”,并且如果ifconfig无作用首先检查root的环境变量是否为sbin 使用echo $PATH,如果环境正常,去sbin下看是否安装了ifconfig,使用 ls /sbin|grep ifconfig ,如果没安装使用yum search ifconfig 安装文件。(yum install net-tools)
前奏:
ip addr 可查看linux ip信息
如果ens33 没有inet 这个属性,那么就没法通过IP地址连接虚拟机
vim /etc/sysconfig/network-scripts/ifcfg-ens33 里的ONBOOT=no需要改为yes,不然无法下载
然后重启网络服务: sudo service network restart
1、配置虚拟机网络连接方式为桥接方式。
(1)IPv4 地址;
(2)子网掩码;
(3)默认网关;
(4)DNS服务器;
3、在虚拟机中输入vim /etc/sysconfig/network-scripts/ifcfg-eth0 插入以下三条信息,vim 编辑器 i 输入,esc退出编辑,:wq保存退出。
IPADDR=IPV4
NETMASK=子网掩码
GATEWAY=默认网关
4、使用vim 打开 /etc/resolv.conf 增加一条nameserver=DNS服务器。
5、重启网络服务service network restart
6、必须开启systemctl防火墙
防火墙的开启、关闭、禁用命令
(1)设置开机启用防火墙:systemctl enable firewalld.service
(2)设置开机禁用防火墙:systemctl disable firewalld.service
(3)启动防火墙:systemctl start firewalld
(4)关闭防火墙:systemctl stop firewalld
(5)检查防火墙状态:systemctl status firewalld
(6)systemctl enable NetworkManager以下提供几个命令参考:
任务 | 旧指令 | 新指令 |
使某服务自动启动 | chkconfig –level 3 httpd on | systemctl enable httpd.service |
使某服务不自动启动 | chkconfig –level 3 httpd off | systemctl disable httpd.service |
检查服务状态 | service httpd status | systemctl status httpd.service |
显示所有已启动的服务 | chkconfig –list | systemctl list-units –type=service |
启动某服务 | service httpd start | systemctl start httpd.service |
停止某服务 | service httpd stop | systemctl stop httpd.service |
重启某服务 | service httpd restart | systemctl restart httpd.service |
7、最后使用systemctl启动,firewall-cmd --zone=public --add-port=80/tcp --permanent
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。