我是在centos7虚拟机上进行实验的

该实验基于添加好ip的基础上,如何给网卡添加ip请查阅我的博客

先来看一下我的ip

[root@localhost nginx]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.128 netmask 255.255.255.0 broadcast 192.168.3.255
inet6 fe80::6b14:b58e:faa2:525 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:5e:7c:27 txqueuelen 1000 (Ethernet)
RX packets 62179 bytes 43830505 (41.8 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 33693 bytes 4570753 (4.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.123 netmask 255.255.255.0 broadcast 192.168.3.255
ether 00:0c:29:5e:7c:27 txqueuelen 1000 (Ethernet) ens33:2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.3.125 netmask 255.255.255.0 broadcast 192.168.3.255
ether 00:0c:29:5e:7c:27 txqueuelen 1000 (Ethernet) 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 185219 bytes 29342174 (27.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 185219 bytes 29342174 (27.9 MiB)
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:61:e7:bc 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 [root@localhost nginx]#

安装好nginx之后(方法有说过了,这里不重复)

安装路径不知道你装哪里,直接 find / -name nginx.conf并进行编辑

[root@localhost nginx]# cat nginx.conf|grep -v "#"|grep -v "^$"
worker_processes 1;#这个参数一般可设为cpu核数,例如我的cpu是i3 3110m,那么这里我就可以通过修改为4来提高性能,但目前我还没进行到那步,所以就先在这里说一下而已
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80; #监听的端口,这里是默认的ip128
server_name localhost; #服务器名
location / {
root html; #网站目录,是nginx安装目录下的html
index index.html index.htm index.php; #默认页面
}
error_page 404 /404.html; #错误页面
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ { #相当于启用php吧
root html; #这里需要根据网站目录进行修改
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server{
listen 192.168.3.123:80;
server_name 192.168.3.123;
access_log logs/bp2.access.log combined; #日志路径,combined 日志格式名称
location /
{
index index.html index.php;
root html/bp2;
}
location ~ \.php$ {
root html/bp2;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} }
server{
listen 192.168.3.125:80;
server_name 192.168.3.125;
location /{
root html/bp3;
index index.html index.php;
}
location ~ \.php$ {
root html/bp3;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
[root@localhost nginx]#

需要重启nginx而已,重启命令 nginx -s reload(这个命令需要进入到sbin文件夹下,不是那个地方都可以的)。

以后注意了,凡是修改了服务器的配置文件,一般都需要重启服务器

[root@localhost nginx]# cat html/bp3/index.php
<?php
echo bp3;
?>
[root@localhost nginx]#

来看一下效果

Nginx配置基于ip的虚拟主机的更多相关文章

  1. nginx配置基于域名的虚拟主机

    其实基于域名和基于ip的虚拟主机配置是差不多的,在配置基于ip的虚拟主机上我们只需要修改几个地方就能变成基于域名的虚拟主机,一个是要修改域名,一个是host文件直接看代码 [root@localhos ...

  2. Apache配置基于IP的虚拟主机 Apache virtual host configuration is based on the IP

    Step 1: 检查是否开启 httpd-vhosts.conf apache/conf/httpd.conf文件 # Virtual hosts Include conf/extra/httpd-v ...

  3. 在Nginx中部署基于IP的虚拟主机

    一.虚拟主机概念 虚拟主机是在网络服务器上划分出一定的磁盘空间供用户放置站点.应用组件等,提供必要的站点功能.数据存放和传输功能.所谓虚拟主机,也叫"网站空间", 就是把一台运行在 ...

  4. Centos6.5中Nginx部署基于IP的虚拟…

    Centos6.5 中Nginx 部署基于IP 的虚拟主机 王尚2014.11.18 一.介绍虚拟主机 虚拟主机是使用特殊的软硬件技术,把一台真实的物理电脑主机 分割成多个逻辑存储单元,每个单元都没有 ...

  5. Nginx总结(二)基于ip的虚拟主机配置

    前面讲了如何安装配置Nginx,大家可以去这里看看nginx系列文章:https://www.cnblogs.com/zhangweizhong/category/1529997.html 今天要说的 ...

  6. CentOS 7运维管理笔记(6)----Apache 基于 IP 的虚拟主机配置

    Apache 配置虚拟主机支持3种方式:基于IP的虚拟主机配置,基于端口的虚拟主机配置,基于域名的虚拟主机配置.本篇随笔记录自己基于IP的虚拟主机配置. 如果同一台服务器有多个IP,可以使用基于IP的 ...

  7. nginx基于IP的虚拟主机

    知识点: server的语法: upstream语法: upstream中192.168.100.1不是ip只是个标识,只要和下面的proxy_pass 对应即可. 基于IP的虚拟主机: listen ...

  8. nginx配置实战1----配置虚拟主机

    1 nginx虚拟主机的概念 虚拟主机是在网络服务器上划分出一定的磁盘空间供用户放置站点.应用组件等,提供必要的站点功能.数据存放和传输功能,所谓虚拟主机,也叫"网站空间",就是把 ...

  9. nginx笔记 安装nginx 配置 反向代理 多虚拟主机

    1,检测linux上是否 通过yum安装了nginxrpm   -qi  nginx 2.安装nginx之前的依赖包yum install gcc patch libffi-devel python- ...

随机推荐

  1. MATLAB 图片折腾4

    重新安排矩阵的x,y,z , 在二维中就相当于把x,y 对换,在三维中相当于可以把三个坐标的位置互换. 比如A = A(:,:,1)=repmat(1,3,3);A(:,:,2)=repmat(2,3 ...

  2. oracle数据导入导出数据与编码格式不正确

     1.导入dmp文件 imp ZHCG/ZHCG@ORCL file=E:\20160902.1007.dmp full=y 2.导出数据 exp system/manager@ORCL file ...

  3. Thêm Một Lần Đau--错错错--IPA--越南语

    越南国际天团HKT的名曲.

  4. sass和scss的区别

    页面引入的时候还是引入的css文件 因为sass和scss都是一种css的预处理工具 目的最后都是生成css文件 sass不带{}和:是基于Ruby 写出来的,严格的缩进方式来控制 scss带这两个 ...

  5. fastIO

    文件系统除了处理正常的IRP 之外,还要处理所谓的FastIo.FastIo是Cache Manager 调用所引发的一种没有irp 的请求.换句话说,除了正常的Dispatch Functions ...

  6. Convert the AScii to SAC file

    readtable *.txt w sac  filename.sac ch delta dela0 w over

  7. 适用于WIFI Hacking的无线网卡推荐

    相信很多初次使用Kali Linux来进行无线渗透的小伙伴都曾遇到过一个非常头疼的问题,就是不知道如何选购一款合适的无线网卡.因为Kali Linux并不是所有的网卡都支持,一旦选错了网卡不仅会给我们 ...

  8. django面试四

    Django的优点 功能完善.要素齐全:自带大量常用工具和框架(比如分页,auth,权限管理), 适合快速开发企业级网站. 完善的文档:经过十多年的发展和完善,Django有广泛的实践案例和完善的在线 ...

  9. HDU 2585 Hotel(字符串的模糊匹配+递归)

    Problem Description Last year summer Max traveled to California for his vacation. He had a great tim ...

  10. 2.28 查看webdriver API

    2.28 查看webdriver API(带翻译) 前言    前面都是点点滴滴的介绍selenium的一些api使用方法,那么selenium的api到底有多少呢?本篇就教大家如何去查看seleni ...