虚拟机下linux系统安装nginx
近在windows虚机下安装nginx,也遇到部分问题,写篇随笔总结一下
一.安装虚机
windows下安装虚拟机我就不说了,一搜一大把,一直下一步就ok了
二. 打开虚拟安装nginx
1.选择版本,下载nginx。下载地址:http://nginx.org/download/
[root@localhost /]# wget http://nginx.org/download/nginx-1.7.0.tar.gz
2.安装pcre openssl gcc库及源码包
[root@nginx /]# yum -y install pcre pcre-devel openssl openssl-devel gcc gcc-c++
3.解压
[root@nginx /]# ll nginx-1.6.3.tar.gz
[root@nginx /]# tar zxvf nginx-1.6.3.tar.gz
[root@nginx /]# cd nginx-1.6.3
[root@nginx nginx-1.7.0]# pwd
/nginx-1.7.0
4.创建nginx用户
[root@nginx nginx-1.7.0]# useradd nginx -s /sbin/nologin -M
5.配置、编译、安装
[root@nginx nginx-1.7.0]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
[root@nginx nginx-1.7.0]# echo $?
0
[root@nginx nginx-1.7.0]# make && make install
[root@nginx nginx-1.7.0]# echo $?
0
[root@nginx nginx-1.7.0]# ln -s /usr/local/nginx/sbin/* /usr/local/sbin
6.启动nginx
[root@nginx nginx-1.7.0]# /usr/local/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx nginx-1.7.0]# /usr/local/sbin/nginx
[root@nginx nginx-1.7.0]# netstat -lntup | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3556/nginx
[root@nginx nginx-1.7.0]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 3556 root 6u IPv4 17544 0t0 TCP *:http (LISTEN)
nginx 3557 nginx 6u IPv4 17544 0t0 TCP *:http (LISTEN)
7.至此nginx启动成功了,我们先在虚拟机中试一下
[root@nginx nginx-1.7.]# curl localhost
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p> <p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p>
</body>
</html>
8.在外部的windows下访问虚拟机中的nginx服务
[root@nginx nginx-1.7.0]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.78.130 netmask 255.255.255.0 broadcast 192.168.78.255
inet6 fe80::3164:48be:dd5f:fa27 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:78:48:f2 txqueuelen 1000 (Ethernet)
RX packets 202596 bytes 299827475 (285.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 107108 bytes 6501152 (6.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 104 bytes 10607 (10.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 104 bytes 10607 (10.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:87:29:e0 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
红色字体部分就是虚拟机的ip地址了,然后我在外部浏览器中访问http://192.168.78.130,发现请求不到服务,原来是因为linux下防火墙的问题,默认使用的fireWall
9.禁用firewalld&开启iptables&systemctl使用简介
9.1.安装
[root@localhost ~]# yum install iptables-services
9.2.屏蔽该服务
[root@localhost ~]# systemctl mask firewalld # systemctl mask firewalld 屏蔽服务(让它不能启动)
# ln -s '/dev/null''/etc/systemd/system/firewalld.service'
# systemctl unmask firewalld 显示服务(如 firewalld.service)
# rm '/etc/systemd/system/firewalld.service'
9.3.启用iptables
[root@localhost ~]# systemctl enable iptables
#如果需要使用 ip6tables , 需另外加一行
[root@localhost ~]# systemctl enable ip6tables
9.4.启动iptables,停止firewalld
#停止firewalld服务,开启 iptables服务
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl start iptables
# 同上,如果需要使用 ip6tables , 需另外加一条
[root@localhost ~]# systemctl start ip6tables
最后在用外部windows浏览器访问:http://192.168.78.130,bingo,可以了
以上就是我安装nginx的整个流程,网上类似的教程很多,我也只是亲身实验,整理了出来。
虚拟机下linux系统安装nginx的更多相关文章
- 虚拟机下Linux系统安装vmtool工具
1.启动此虚拟机2.用超级用户root登录3.登录成功后,Ctrl+Alt ,取出鼠标,点选菜单栏,虚拟机 →安装VMware工具 → Install4.待虚拟系统挂载了光盘后,弹出cdrom文件夹或 ...
- 2-0 虚拟机与Linux系统安装
虚拟机与Linux系统安装 虚拟机硬件选择 由于是初学Linux,所以我们通过在虚拟机里安装的方式学习Linux,如果不知道找虚拟机和Linux的话请看我上一篇博客:计算机基础 如果你已经准备好了虚拟 ...
- 虚拟机下Linux读取USB设备的问题虚拟机下Linux无法读取USB设备的解决方案
我们在虚拟机中识别USB设备有三种情况导致Linux系统不能读取到USB设备: 1. .当虚拟机的USB服务没有开启的时候 2. 若虚拟机的USB连接的设置选项没有设置好 3. Widows抢先一步, ...
- 虚拟机下Linux系统如何设置IP地址
虚拟机下Linux系统设置IP地址三种方法 文章来源:https://jingyan.baidu.com/article/ea24bc399ffeb9da62b3318f.html 工具/原料 V ...
- 虚拟机下linux迁移造成MAC地址异常处理办法
虚拟机下linux迁移造成MAC地址异常处理办法 Linux无法启用网卡:Device eth0 has different MAC address than expected,ignoring解决 ...
- Vmware安装与VMware下Linux系统安装
源文件地址:http://www.cnblogs.com/lclq/p/5619271.html 1.下载安装VMware,我安装的是VMware 12.VMware从11开始不再支持32位系统,32 ...
- 虚拟机下linux安装mysql,apache和php
由于腿伤了,卧床在家折腾下linux,尝试用虚拟机装mysql,apche和php.中间各种波折,装了好几天,觉得有些经验还是要记录下来,让自己别忘了:) 按照下面这篇文章的方法,基本可以顺利安装成功 ...
- VMware虚拟机下Linux系统的全屏显示
在VMware虚拟机下的Linux无法全屏的问题的解决方案如下: 1. 启动虚拟机,并启动Redhat6.4. 2. 点击“view”——然后将Autofit window这个选项勾选.(一般 ...
- 虚拟机、linux系统安装
下载VMWare解压后依据提示正触安装VMWare到硬盘中 (1) 建立虚拟机 A.用鼠标左建双击桌面中的"VMwareworkstation"图标.执行虚拟机 B.建立一台虚拟机 ...
随机推荐
- 【MySQL疑难杂症】如何将树形结构存储在数据库中(方案一、Adjacency List)
今天来看看一个比较头疼的问题,如何在数据库中存储树形结构呢? 像mysql这样的关系型数据库,比较适合存储一些类似表格的扁平化数据,但是遇到像树形结构这样有深度的人,就很难驾驭了. 举个栗子:现在有一 ...
- 全本 | iKcamp翻译 | 《JavaScript 轻量级函数式编程》|《你不知道的JS》姊妹篇
原文地址:Functional-Light-JS 原文作者:Kyle Simpson - <You-Dont-Know-JS>作者 译者团队(排名不分先后):阿希.blueken.bruc ...
- 小白的Python之路 day1 用户输入
1 2 3 4 5 6 7 8 #!/usr/bin/env python #_*_coding:utf-8_*_ username =input("username:") p ...
- windows MySQL 5.6.38 安装步骤
文章转载于此出 mysql5.6.38 1067错误 可能是自己添加 了my.ini文件 其实不需要添加这个文件,直接在mydefault.ini中修改就行了 mysql 5.6 zip解压安装配置( ...
- VSCode插件及用户设置
第一部分:插件 VSCode内置"emmet"插件,"convert to utf-8"等插件效果!十分强大!代码提示功能特别强悍! 插件地址:点击此处! 推荐 ...
- 一道看似dp实则暴力的题 Zombie's Treasure Chest
Zombie's Treasure Chest 本题题意:有一个给定容量的大箱子,此箱子只能装蓝宝石和绿宝石,假设蓝绿宝石的数量无限,给定蓝绿宝石的大小和价值,要求是获得最大的价值 题解:本题看似是 ...
- Tabhost中Activity绑定Service
在android中,一个Activity绑定一个Service组件我们一般用Context().bindService方法就能够.可是假设这个 Activity属于一个Tabhost的话就不行了,在网 ...
- linux 开机批量启动程序
每天早上到公司第一件事打开电脑,打开我的qq.我的开发工具idea.在看看邮件,日复一日,变懒了.也变聪明了,写了以下一段脚本 文件名称:mystart.sh #!bin/bash #检验我的开发工具 ...
- (四)—性能测试工具curl-loader(linux)
curl-loader介绍 curl-loader(也被称为"omes-NIK"和"davilka")是一个开源的C语言编写的工具,模拟应用负载和成千上万的几十 ...
- vue-router实例
最近刚刚用vue写了个公司项目,使用vue-cli构建的,算是中大型项目吧,然后这里想记录并且分享一下其中的知识点,希望对大家有帮助,后期会逐渐分享:话不多说,直接上代码!! main.js // T ...