<一、参考>

这里以配置2个站点(2个域名)为例,n 个站点可以相应增加调整,假设:

IP地址: 202.55.1.100

域名1 example1.com 放在 /www/example1

配置 nginx virtual hosting 的基本思路和步骤如下:

把这个站点 example1.com放到 nginx 可以访问的目录 /www/

给每个站点分别创建一个 nginx 配置文件 example1.com.conf, 并把配置文件放到 /etc/nginx/vhosts/

然后在 /etc/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号)

重启 nginx

具体过程

下面是具体的配置过程:

1、在 /etc/nginx 下创建 vhosts 目录

mkdir /etc/nginx/vhosts

2、在 /etc/nginx/vhosts/ 里创建一个名字为 example1.com.conf 的文件,把以下内容拷进去

server {

listen 80;

server_name example1.com www. example1.com;

#access_log /www/access_ example1.log main;

location / {

root /www/example1.com;

index index.php index.html index.htm;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root /usr/share/nginx/html;

}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

location ~ \.php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /www/example1.com/$fastcgi_script_name;

include fastcgi_params;

}

location ~ /\.ht {

deny all;

}

}

3、打开 /etc/nginix.conf 文件

将下面这句在nginx.conf 文件的最后一行,目的引入刚才的vhosts文件

include /usr/local/etc/nginx/vhosts/*;

5、重启 Nginx

/etc/init.d/nginx restart

或者 kill -HUP `cat /var/run/nginx.pid`     cat 后面跟的是nginx进程pid  如果不知道nginx.pid文件的位置可以用find / -name nginx.pid 命令来查找

或用yum源码包安装的nginx可以直接service nginx restart

</参考>

<二、我的实例>

--------- vhosts/led.conf

server {
        listen       80;
        server_name   www.led.com
        index index.html index.htm index.php;
        root /usr/local/vhost/led;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
            root  /usr/local/vhost/led;
            index  index.html index.htmindex.php;
        }

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
 
    location ~ .*\.(php|php5)?$
       {
        #fastcgi_pass unix:/tmp/php-cgi.sock;
         fastcgi_pass  127.0.0.1:9000;
         fastcgi_index index.php;
         fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include fastcgi_params;
       }

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
       {
        expires 30d;
       }

location ~ .*\.(js|css)?$
      {
       expires 1h;
       }

log_format access '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                         '"$http_user_agent" $http_x_forwarded_for';
       
    }

---------------- nginx.conf

user  nginx nginx;
worker_processes  8;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        /usr/local/nginx/nginx.pid;

worker_rlimit_nofile 65535;
events {
    use epoll;
    worker_connections  65535;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;

sendfile        on;
    tcp_nopush     on;

#keepalive_timeout  0;
    keepalive_timeout  65;

tcp_nodelay on;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

gzip  on;
    gzip_min_length 1k;
    gzip_buffers   4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types   text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

server {

listen 80;

server_name _;

server_name_in_redirect off;

location / {

root /usr/share/nginx/html;

index index.html;

}

}

# 包含所有的虚拟主机的配置文件

include /usr/local/nginx/conf/vhosts/*;
      
}

文章摘自 http://blog.sina.com.cn/s/blog_66ac09390101ivep.html

lnmp下配置PHP虚拟主机vhost相关推荐

  1. Linux下配置Apache虚拟主机(基于IP地址)

    Linux下配置Apache虚拟主机(基于IP地址) 一.虚拟主机 虚拟主机,又称虚拟服务器,是一种在单一主机或主机群上,实现多网域服务的方法,可以运行多个网站或服务的技术.虚拟主机之间完全独立,并可 ...

  2. Ubuntu系统下配置Apache虚拟主机

    本文已在本人博客https://www.nsxsg.com/archives/125首发 文章目录 Ubuntu系统下配置Apache虚拟主机 说明 配置文件 配置多个虚拟主机 Ubuntu系统下配置 ...

  3. WIN10 vagrant和virtualbox虚拟机和一键搭建lnmp环境配置thinkphp虚拟主机

    版本:win10系统 virtualbox:5.1.26 vagrant :1.9.7 centos 7.0 xshell/git 首先下载好对应版本的软件 配置vagrant和virtualbox ...

  4. CentOS下配置apache虚拟主机

    1.apache虚拟主机配置: (1)基于域名的配置(同一个IP不同域名)方法:    ①添加域名到hosts文件中, 命令vim /etc/hosts 添加的内容: 192.168.142.140 ...

  5. mac下配置apache虚拟主机

    为什么要配置虚拟主机 访问web服务,本质上看(从协议上)是访问某个IP的主机上的某个端口(默认是80) 通常需要通过访问不同的域名或者端口实现对不同网站的访问(具体到服务器里就是不同目录),这个时候 ...

  6. windows下配置apache虚拟主机

    其中一部分,以后会慢慢更新完整过程 apache目录下conf目录下的httpd.conf文件中修改为 <VirtualHost *:80>      ServerAdmin kefu@i ...

  7. lnmp下配置虚拟主机

    一:首先熟悉几个命令 which php      --->  which是通过 PATH环境变量到该路径内查找可执行文件,所以基本的功能是寻找可执行文件 whereis php   ----& ...

  8. 在CentOS 8上安装与配置Apache虚拟主机

    实验环境 操作系统:Centos 8 web应用:apache 内网IP:192.168.3.21 shell执行:root 以root或具有sudo权限的用户身份登录执行如下操作. 主配置文件路径: ...

  9. 打开虚拟服务器设置,什么样配置的虚拟主机打开网站快

    什么样配置的 虚拟主机,是从 网站打开速度快,与虚拟主机配置.网站程序.网站数据等都有关系.我们接下来,专门讲下虚拟主机配置,暂不考虑网站层面影响. 虚拟主机配置高,相应网站打开会快些,那么哪些虚拟主 ...

  10. 16.4 配置Tomcat监听80端口 16.5/16.6/16.7 配置Tomcat虚拟主机16.8 Tomcat日志

    2019独角兽企业重金招聘Python工程师标准>>> 16.4 配置Tomcat监听80端口 直接访问,使用默认的web服务,需要改动端口为80,如果不是80端口那么访问页面的时候 ...

最新文章

  1. 代码居中对齐_一篇文章带你了解CSS对齐方式
  2. 数据挖掘中分类算法小结
  3. 2018/12/07 L1-033 出生年 Java
  4. PostgreSQL · 特性介绍 · 全文搜索介绍
  5. 【直播预告】中外互联网大厂欢乐开撕:谁是技术界的嘴炮王者?
  6. JAVA——实现七牛云对象存储Region对象采用配置方式生成解决方案
  7. linux下json数据解析,Linux下使用jq简单解析json的方法
  8. One Order CLOSING date修改后的执行原理
  9. 352. 将数据流变为多个不相交区间
  10. 前端wxml取后台js变量值_微信小程序云开发教程WXML入门数据绑定
  11. c++ stl队列初始化_创建一个向量,并将其像C ++ STL中的数组一样初始化
  12. 12002.i2ctools工具
  13. 条件锁pthread_cond_t 的应用
  14. python和c的语法区别_python与c语言的语法有哪些不一样的
  15. 用API实现串口异步读写
  16. python 打开本地程序发生异常_Python中的异常处理
  17. 如何合理封装你的轮子、飞机、大炮(以封装OkHttp为例)
  18. 计算机系统变慢的原因,重装系统后电脑变得很慢原因分析及解决办法
  19. 谱尼软件测试谱尼为网络安全护航
  20. 想进Google,先来做做Google招聘题

热门文章

  1. 空气炸锅如何挑选研究
  2. 用计算机怎么管理小米路由器,小米路由器3G怎么设置?(电脑)
  3. 自己写的年会抽奖软件免费版带后门作弊,共享出来给大家(更新至V1.3)——转自哈尔滨健康生活网
  4. RTI DDS. c++11例子 -1
  5. 计算机建立第2用户,2016年计算机二级VF备考练习题及参考答案(5)
  6. 第十届蓝桥杯大赛软件类省赛 Java 大学 B组 试题H:人物相关性分析
  7. 全球化业务渐入佳境,BIGO盈利持续大幅提升,是时候重估欢聚集团
  8. 设置jsp打开的默认方式
  9. Debian10安装部署DNS服务-正向解析篇
  10. dns服务器修复视频,修复dns异常最为简单的方法,一起学习吧