lnmp下 nginx 配置虚拟主机
<一、参考>
这里以配置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 配置虚拟主机的更多相关文章
- windows 下 nginx 配置虚拟主机
1. 在 nginx 的配置文件 nginx.conf 里面 引入虚拟主机配置文件,以后所有的虚拟主机配置文件都在写这个文件里 include vhost.conf; (或者新建vhost ...
- windows和mac下分别配置虚拟主机
windows下配置 1.找到apache的配置文件,httpd.conf 2.找到 LoadModule rewrite_module modules/mod_rewrite.so 去掉前边的# 3 ...
- nginx配置虚拟主机vhost的方法详解
Nginx vhost配置,可实现基于ip.端口号.servername的虚拟主机,同时可避免直接修改主配置文件.在nginx下配置虚拟主机vhost非常方便.这篇文章主要介绍了nginx配置虚拟主机 ...
- nginx 配置虚拟主机
文章转载自:http://www.ttlsa.com/html/1571.html 上篇说道我们的nginx是安装在/usr/local/nginx/ cd conf 我们现在把所有的虚拟主机放在一个 ...
- nginx 配置虚拟主机的三种方法
nginx,一个server标签就是一个虚拟主机. 1.基于域名的虚拟主机,通过域名来区分虚拟主机——应用:外部网站 2.基于端口的虚拟主机,通过端口来区分虚拟主机——应用:公司内部网站,外部网站的管 ...
- nginx配置虚拟主机、反向代理和负载均衡
为了实现这个功能,需要修改nginx的配置文件,将nginx.conf清理一下,使结构更清晰. worker_processes ; events { worker_connections ; } h ...
- nginx配置虚拟主机之不同端口和不同IP地址
配置nginx虚拟主机不同端口和不同ip地址,和上编nginx基于域名配置虚拟主机博文类似,请先参考. zxl.com域名不同端口,配置文件内容如下: 1 2 3 4 5 6 7 8 9 10 11 ...
- nginx 配置虚拟主机访问PHP文件 502错误的解决方法
最近配置Nginx 服务器虚拟主机 访问目录发现报502错误 百度了很多方法 都不管用 我擦 各种抓狂----- 原本Nginx配置如下: 网上找了很多方法: 查看日志 借助nginx的错误日志 ...
- Nginx笔记总结五:Nginx配置虚拟主机
upstream proxy1 { server ; } upstream proxy2 { server ; } server { listen ; server_name www1.dlab.co ...
随机推荐
- SQL的主键和外键和唯一约束
SQL的主键和外键的作用: 外键取值规则:空值或参照的主键值. (1)插入非空值时,如果主键表中没有这个值,则不能插入. (2)更新时,不能改为主键表中没有的值. (3)删除主键表记录时,你可以在建外 ...
- stein法求gcd 学习笔记
原理显然 由于当x,y都为奇数时进行辗转相见 每次减完必有偶数 而偶数最多除log次 那么也最多减log次 复杂度有保证 注:代码未验证 int gcd(int x,int y){ int res=1 ...
- 如何从sql server导出到csv文件
如何从sql server导出到csv文件,具体代码如下: private static void WriteHeader(SqlDataReader reader, TextWriter outpu ...
- 【BZOJ1059】矩阵游戏(二分图最大匹配)
题意:矩阵游戏在一个N*N黑白方阵进行.每次可以对该矩阵进行两种操作: 行交换操作:选择矩阵的任意两行,交换这两行(即交换对应格子的颜色) 列交换操作:选择矩阵的任意行列,交换这两列(即交换对应格子的 ...
- Linux 之 文件压缩解压
文件压缩解压 参考教程:[千峰教育] 命令: gzip: 作用:压缩文件,只能是单个文件,不能是多个,也不能是目录. 格式:gzip file 说明:执行命令会生成file.gz,删除原来的file ...
- hdu 1186(搜索+HASH)
方程的解数 Time Limit: 15000MS Memory Limit: 128000K Total Submissions: 7045 Accepted: 2417 Case Time ...
- 空间划分的数据结构(网格/四叉树/八叉树/BSP树/k-d树/BVH/自定义划分)
目录 网格 (Grid) 网格的应用 四叉树/八叉树 (Quadtree/Octree) 四叉树/八叉树的应用 BSP树 (Binary Space Partitioning Tree) 判断点在平面 ...
- Hdoj 3506 Monkey Party
Discription Far away from our world, there is a banana forest. And many lovely monkeys live there. O ...
- springboot idea激活指定profile
多Profile文件 配置文件编写的时,可以是application-{profile}.properties/yml,默认使用application.properties的配置: 激活指定profi ...
- BZOJ2527Meteors
BZOJ2527 整体二分模板题 整体二分: 主要用于解决第K大问题 #include<cstdio> #include<cctype> #include<vector& ...