近在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的更多相关文章

  1. 虚拟机下Linux系统安装vmtool工具

    1.启动此虚拟机2.用超级用户root登录3.登录成功后,Ctrl+Alt ,取出鼠标,点选菜单栏,虚拟机 →安装VMware工具 → Install4.待虚拟系统挂载了光盘后,弹出cdrom文件夹或 ...

  2. 2-0 虚拟机与Linux系统安装

    虚拟机与Linux系统安装 虚拟机硬件选择 由于是初学Linux,所以我们通过在虚拟机里安装的方式学习Linux,如果不知道找虚拟机和Linux的话请看我上一篇博客:计算机基础 如果你已经准备好了虚拟 ...

  3. 虚拟机下Linux读取USB设备的问题虚拟机下Linux无法读取USB设备的解决方案

    我们在虚拟机中识别USB设备有三种情况导致Linux系统不能读取到USB设备: 1. .当虚拟机的USB服务没有开启的时候 2. 若虚拟机的USB连接的设置选项没有设置好 3. Widows抢先一步, ...

  4. 虚拟机下Linux系统如何设置IP地址

    虚拟机下Linux系统设置IP地址三种方法 文章来源:https://jingyan.baidu.com/article/ea24bc399ffeb9da62b3318f.html 工具/原料   V ...

  5. 虚拟机下linux迁移造成MAC地址异常处理办法

    虚拟机下linux迁移造成MAC地址异常处理办法 Linux无法启用网卡:Device eth0 has different MAC address than expected,ignoring解决 ...

  6. Vmware安装与VMware下Linux系统安装

    源文件地址:http://www.cnblogs.com/lclq/p/5619271.html 1.下载安装VMware,我安装的是VMware 12.VMware从11开始不再支持32位系统,32 ...

  7. 虚拟机下linux安装mysql,apache和php

    由于腿伤了,卧床在家折腾下linux,尝试用虚拟机装mysql,apche和php.中间各种波折,装了好几天,觉得有些经验还是要记录下来,让自己别忘了:) 按照下面这篇文章的方法,基本可以顺利安装成功 ...

  8. VMware虚拟机下Linux系统的全屏显示

    在VMware虚拟机下的Linux无法全屏的问题的解决方案如下: 1.   启动虚拟机,并启动Redhat6.4. 2.   点击“view”——然后将Autofit window这个选项勾选.(一般 ...

  9. 虚拟机、linux系统安装

    下载VMWare解压后依据提示正触安装VMWare到硬盘中 (1) 建立虚拟机 A.用鼠标左建双击桌面中的"VMwareworkstation"图标.执行虚拟机 B.建立一台虚拟机 ...

随机推荐

  1. DIV居中的经典方法

    1. 实现DIV水平居中 设置DIV的宽高,使用margin设置边距0 auto,CSS自动算出左右边距,使得DIV居中. 1 div{ 2 width: 100px; 3 height: 100px ...

  2. 原生javascript选项卡

    js选项卡是一个常用的实现.这里我们将用原生js来将其给予实现. 首先html代码: <div id="container"> <input type=" ...

  3. Spring Cloud 前后端分离后引起的跨域访问解决方案

    背景 Spring Cloud 微服务试点改造,目前在尝试前后端分离. 前台A应用(本机8080端口),通过网管(本机8769端口)调用后台应用B(本机8082端口).应用C发布的http服务.. A ...

  4. django模板语法之include

    假如我们有以下模板index.html,代码为: <!DOCTYPE html> <html lang="en"> <head> <met ...

  5. ubuntu更换开机动画

    ubuntu更换启动动画 作为一个个用linux作为桌面环境,并且完全替代了windows的来说,怎么折腾好看,是一个重要的问题,而Ubuntu的开机动画,那紫色的画面,ubuntu那几个大字,实在丑 ...

  6. EFCore2.0 Code First基本使用

    前言 在网上找EFCore Code First相关的文章,很多都是基于core 1.0版本的,觉得有必要自己实践下2.0.所以,撸起袖子干吧!~ 1.新建控制台项目(这里就不放图了) 2.打开程序包 ...

  7. .NET作品集:linux下的.net mvc cms

    cms程序架构 本程序是主要是用于企业网站开发的,也可以做博客程序,程序是从之前上一篇的.net 博客程序改进过来的,主要技术由webform转成.net mvc了,由于是很早之前的项目,12年还是m ...

  8. 数学之美?编程之美?数学 + 编程= unbelievable 美!

    欢迎大家前往腾讯云社区,获取更多腾讯海量技术实践干货哦~ 作者:Rusu 导语 相信大家跟我一样,偶尔会疑惑:曾经年少的时候学习过的那么多的复杂的数学函数,牛逼的化学方程式,各种物理原理.公式,到底有 ...

  9. 详解Office Add-in 清单文件

    作者:陈希章 发表于2017年12月8日 前言 我们都知道,一个Office Add-in,最主要是由两个部分组成的:清单文件(manifest)和真正要用来执行的网站. 清单文件其实是一个标准的XM ...

  10. Elasticsearch短语搜索——match_phrase

    找出一个属性中的独立单词是没有问题的,但有时候想要精确匹配一系列单词或者短语 . 比如, 我们想执行这样一个查询,仅匹配同时包含 "rock" 和 "climbing&q ...