我是在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. sql语句最后一行显示统计。

    SELECT id, username, id_Num FROM users UNION ALL SELECT '合计', count(*), null FROM users ORDER BY id_ ...

  2. svn服务器搭建及使用(一)

    这里郑重感谢分享作者的辛苦:http://www.cnblogs.com/xiaobaihome/archive/2012/03/20/2407610.html Subversion是优秀的版本控制工 ...

  3. 【转载】Maven中的BOM概念

    1.概述 1.1.什么是 BOM? BOM stands for Bill Of Materials. A BOM is a special kind of POM that is used to c ...

  4. Centos7安装配置iptable

    CentOS7默认的防火墙不是iptables,而是firewalle. 安装iptable iptable-service #先检查是否安装了iptables service iptables st ...

  5. CSS学习笔记-02. 2D转换模块-形变中心点

    简单粗暴,直接上重点:  transform-origin 接下来是代码. 首先 勾勒出 3个重叠的div 接着 给3个div分别添加 transform: rotate . <!DOCTYPE ...

  6. SharePoint Framework 在Visual Studio Code中调试你的托管解决方案

    博客地址:http://blog.csdn.net/FoxDave 上一篇介绍了如何在本地调试你的SharePoint Framework解决方案,本篇介绍如何调试你的SharePoint Onl ...

  7. cf467D(map,vector,bfs,特点提取)

    D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Java不同类型字符转换String/int/Float/////

    1.int & String int i=5678;String s=""; int->String: s=i+"";或 s=String.val ...

  9. 『翻译』Access USB Devices on the Web

    https://developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web Access USB Devices o ...

  10. curl 返回头部和正文

    头部string(195) "HTTP/1.1 200 OK Server: openresty/1.7.7.1 Date: Wed, 05 Sep 2018 13:18:33 GMT Co ...