我是在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. Mac生成rsa证书

    详细参考大神 https://blog.csdn.net/qq_30513483/article/details/51242338 RSA为一种加密算法,生成的文件格式有两种,一种是PEM格式,另一种 ...

  2. C++输出数组名

    1.如果C++输出的数组是char类型的,那么输出的就是数组中的元素. 2.如果使用的是其他类型的数组作为输出的话,那么就是一个16进制的地址. 3.还是那句话,对数组的操作,很多时候都是指针的操作, ...

  3. Problem B 字符串类(I)

    封装一个字符串类,用于存储字符串和处理的相关功能,支持以下操作: 1. STR::STR()构造方法:创建一个空的字符串对象. 2. STR::STR(const char *)构造方法:创建一个字符 ...

  4. POJ 2407 Relatives(欧拉函数入门题)

    Relatives Given n, a positive integer, how many positive integers less than n are relatively prime t ...

  5. nginx——防盗链功能

    我们经常会看到在浏览某一图片时会弹出一“403权限禁止”错误,这说明有可能正在浏览的这个网站用到的图片在盗用别的网站图片,而被盗用的网站采用了防盗链技术.那么怎样才能不让自己的网站受害呢? 下面我来介 ...

  6. REST easy with kbmMW #16 – Multiple servers using HTTP.sys transport

    前文写过使用HTTP.sys转输层(TkbmMWHTTPSysServerTransport),实现一个kbmMW应用服务器. 如果在一台服务器上,同时运行多个,基于TkbmMWHTTPSysServ ...

  7. python生产者消费者模型优点

    生产者消费者模型:解耦,通过队列降低耦合,支持并发,生产者和消费者是两个独立的并发体,他们之间使用缓存区作为桥梁连接,生产者指望里丢数据,就可以生产下一个数据了,消费者从中拿数据,这样就不会阻塞,影响 ...

  8. HDU 6045 17多校2 Is Derek lying?

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=6045 Time Limit: 3000/1000 MS (Java/Others)    Memory ...

  9. ubuntu: firefox+flashplay

    更新两步: 1.安装firefox:rm-->下载-->mv-->ln http://www.cnblogs.com/yzsatcnblogs/p/4266985.html 2. f ...

  10. pip windows下的引入

    安装了python以后,并且环境变量里引入了python安装路径后, 想使用pip来安装未安装的模块,但是命令模式里不能执行pip, 查看python安装路径,发现pip跟easy_install的执 ...