<一、参考>
这里以配置2个站点(2个域名)为例,n 个站点可以相应增加调整,假设:
IP地址: 202.55.1.100
域名1 example1.com 放在 /www/example1
域名2 example2.com 放在 /www/example2
配置 nginx virtual hosting 的基本思路和步骤如下:
把2个站点 example1.com, example2.com 放到 nginx 可以访问的目录 /www/
给每个站点分别创建一个 nginx 配置文件 example1.com.conf,example2.com.conf, 并把配置文件放到 /etc/nginx/vhosts/
然后在 /etc/nginx.conf(注:该路径也可能是自定义的,不一定就在/etc目录下) 里面加一句 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/nginx/vhosts/ 里创建一个名字为 example2.com.conf 的文件,把以下内容拷进去
server {
listen 80;
server_name example2.com www. example2.com;
access_log /www/access_ example1.log main;
location / {
root /www/example2.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/example2.com/$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
4、打开 /etc/nginix.conf 文件,在相应位置加入 include 把以上2个文件包含进来
user nginx;
worker_processes 1;
# main server error log
error_log /var/log/nginx/error.log ;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
# main server config
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”‘;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name _;
access_log /var/log/nginx/access.log main;
server_name_in_redirect off;
location / {
root /usr/share/nginx/html;
index index.html;
}
}
# 包含所有的虚拟主机的配置文件
include /usr/local/etc/nginx/vhosts/*;
}
5、重启 Nginx
/etc/init.d/nginx restart

附:设置防火墙:

vi /etc/sysconfig/iptables

假设要开放8888端口

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8888 -j ACCEPT

重启防火墙:

/etc/init.d/iptables restart

lnmp下 nginx 配置虚拟主机的更多相关文章

  1. windows 下 nginx 配置虚拟主机

    1. 在 nginx 的配置文件 nginx.conf 里面 引入虚拟主机配置文件,以后所有的虚拟主机配置文件都在写这个文件里 include       vhost.conf; (或者新建vhost ...

  2. windows和mac下分别配置虚拟主机

    windows下配置 1.找到apache的配置文件,httpd.conf 2.找到 LoadModule rewrite_module modules/mod_rewrite.so 去掉前边的# 3 ...

  3. nginx配置虚拟主机vhost的方法详解

    Nginx vhost配置,可实现基于ip.端口号.servername的虚拟主机,同时可避免直接修改主配置文件.在nginx下配置虚拟主机vhost非常方便.这篇文章主要介绍了nginx配置虚拟主机 ...

  4. nginx 配置虚拟主机

    文章转载自:http://www.ttlsa.com/html/1571.html 上篇说道我们的nginx是安装在/usr/local/nginx/ cd conf 我们现在把所有的虚拟主机放在一个 ...

  5. nginx 配置虚拟主机的三种方法

    nginx,一个server标签就是一个虚拟主机. 1.基于域名的虚拟主机,通过域名来区分虚拟主机——应用:外部网站 2.基于端口的虚拟主机,通过端口来区分虚拟主机——应用:公司内部网站,外部网站的管 ...

  6. nginx配置虚拟主机、反向代理和负载均衡

    为了实现这个功能,需要修改nginx的配置文件,将nginx.conf清理一下,使结构更清晰. worker_processes ; events { worker_connections ; } h ...

  7. nginx配置虚拟主机之不同端口和不同IP地址

    配置nginx虚拟主机不同端口和不同ip地址,和上编nginx基于域名配置虚拟主机博文类似,请先参考. zxl.com域名不同端口,配置文件内容如下: 1 2 3 4 5 6 7 8 9 10 11 ...

  8. nginx 配置虚拟主机访问PHP文件 502错误的解决方法

    最近配置Nginx 服务器虚拟主机 访问目录发现报502错误 百度了很多方法 都不管用  我擦 各种抓狂----- 原本Nginx配置如下: 网上找了很多方法: 查看日志   借助nginx的错误日志 ...

  9. Nginx笔记总结五:Nginx配置虚拟主机

    upstream proxy1 { server ; } upstream proxy2 { server ; } server { listen ; server_name www1.dlab.co ...

随机推荐

  1. 线段树懒标记好题 HDU4578

    (1)"1 x y c",代表 把区间 [x,y] 上的值全部加c (2)"2 x y c",代表 把区间 [x,y] 上的值全部乘以c (3)"3 ...

  2. CodeForces 232E.Quick Tortoise

    John Doe has a field, which is a rectangular table of size n × m. We assume that the field rows are ...

  3. 使用 new Q_max_capacity 參數,同樣 loading 下,粗估耗電量(UI 上的 %)。

    Precondition : 除了 Q_max 外,其它參數皆同. old Q_max_capacity : 1500 mAh new Q_max_capacity : 2200 mAh 有一個 lo ...

  4. Scrapy学习-19-远程管理telnet功能

    使用scrapy的telnet功能远程管理scrapy运行 用法 telnet <IP_ADDR> <PORT> 官方文档 https://doc.scrapy.org/en/ ...

  5. [深入学习C#]C#实现多线程的方式:Task——任务

    简介 .NET 4包含新名称空间System.Threading.Tasks,它 包含的类抽象出了线程功能. 在后台使用ThreadPool. 任务表示应完成的某个单元的工作. 这个单元的工作可以在单 ...

  6. 微信小程序 之wx.getLocation()获取地理信息中的小坑

    提到wx.getLocation()这个方法,大家都知道是获取地理信息的 今天用这个方法获取定位经纬度后传给后台取得附近markers标记集合, 在开发工具上都正常有标记出现 ,但是在手机测试时,死活 ...

  7. waypoint+animate元素滚动监听触发插件实现页面动画效果

    最近在做一个官网类型滚动加载动画,使用到waypoint监听事件插件和animate动画样式,两者结合完美实现向下滚动加载动画,但是没有做向上滚动撤消动画,留待以后有空研究 首先来介绍下jquery. ...

  8. 22. Spring Boot 拦截器HandlerInterceptor【从零开始学Spring Boot】

    转:http://blog.csdn.net/linxingliang/article/details/52069495 上一篇对过滤器的定义做了说明,也比较简单.过滤器属于Servlet范畴的API ...

  9. Linux mm相关的问题

    [S]为什么High MEM是从896M開始的? As the running kernel needs these functions, a region of at least VMALLOC_R ...

  10. flex操作XML,强力总结帖

    初始化XML对象 XML对象可以代表一个XML元素.属性.注释.处理指令或文本元素.在ActionScript 3.0中我们可以直接将XML数据赋值给变量: var myXML:XML =    &l ...