1、nginx.conf 文件,路径为:/etc/nginx/agin.conf

#使用的用户和组
user www-data; #指定工作衍生进程数(一般等于CPU总核数或总核数的两倍)
worker_processes 4; #指定PID存放的路径
pid /run/nginx.pid; #指定文件描述符数量
worker_rlimit_nofile 51200; events {
#使用的网络I/O模型,linux戏台推荐采用epoll模型,freebsd系统采用kqueue模型
use epoll; #允许最大连接数
worker_connections 51200;
# multi_accept on;
} http { ##
# 基础设置
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off; server_names_hash_bucket_size 128;
# server_name_in_redirect off; include /etc/nginx/mime.types;
default_type application/octet-stream; ##
# 日志设置
##
#指定错误日志存放路径数, 错误日志记录的级别可选项为:[debug|info|notice|warn|error|crit]
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log; ##
# 压缩设置
##
gzip on;
gzip_disable "msie6"; gzip_vary on;
# gzip_proxied any;
gzip_comp_level 2;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; ##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
## #include /etc/nginx/naxsi_core.rules; ##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
## #passenger_root /usr;
#passenger_ruby /usr/bin/ruby; ##
# 虚拟主机设置
## include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
} #mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}

2、default 服务主机配置文件,路径为:/etc/nginx/sites-available/default

#主机
server {
listen 80;
server_name www.demo.com;
root /home/zxl/wwwroot/demo/;
index index.php index.html index.htm; #如果没有可访问目录或文件
if (!-e $request_filename) {
#将访问路径跳转至根目录下的index.php接受处理
rewrite ^/(.*)$ /index.php/$1 last;
break;
} #处理请求路径满足匹配 .php 的响应
   # “ location ~ \.php ” == “ location ~ \.php($|/) ”
   #第一句的意思是如果请求字符中匹配到“ .php ”字符,就交给php解析器处理
   #第二句的意思是如果请求字符中匹配到以“ .php ”字符为结尾的或 “ .php/ ” 字符,就交给php解析器处理
   #推荐采纳第二句
location ~ \.php($|/)
{
#响应请求处理入口,使用php-fpm进行管理
fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} #配置静态图片文件客户端缓存时间
location ~ .*\.(gif|jgp|jpeg|png|bmp|swf)$
{
expires 30d; #30天
} #配置js、css文件客户端缓存时间
location ~ .*\.(js|css)?$
{
expires 1h; #1小时
} #设置访问日志保存格式
#log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer"' '"$http_user_agent" $http_x_forwarded_for'; #设置访问日志保存路径
#access_log /var/log/nginx/access.log access;
}

虚拟主机的绑定:
可以是同主机多IP,二是同IP多虚拟主机方式。
同主机多IP的方式,是使用网卡回环功能,同一网卡绑定多个ip。

同IP多虚拟主机方式(推荐,很适合开发者同时开发多个项目的情况下使用):
本地开发的时侯给每个虚拟主机设定一个域名,
编辑 /etc/hosts 文件:

127.0.0.1        www.demo.com
127.0.0.1 www.demo2.com
127.0.0.1 www.demo3.com

在编辑 /etc/nginx/sites-available/default 文件

service{
******
}

拷贝该代码体,复制你要的虚拟机个数数。

再编辑

    server_name www.demo2.com; //设置为你设定好的域,依次类推
root /home/zxl/wwwroot/demo2;

最终如下:

#demo
server {
listen 80;
server_name www.demo.com;
root /home/zxl/wwwroot/demo/;
index index.php index.html index.htm; if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
} location ~ \.php
{
#响应请求处理入口,使用php-fpm进行管理
fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} location ~ .*\.(gif|jgp|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';
#access_log /var/log/nginx/access.log access;
} #demo2
server {
listen 80;
server_name www.demo2.com;
root /home/zxl/wwwroot/demo2/;
index index.php index.html index.htm; if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
} location ~ \.php
{
#响应请求处理入口,使用php-fpm进行管理
fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} location ~ .*\.(gif|jgp|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';
#access_log /var/log/nginx/access.log access;
} #demo3
server {
listen 80;
server_name www.demo3.com;
root /home/zxl/wwwroot/demo3/;
index index.php index.html index.htm; if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
break;
} location ~ \.php
{
#响应请求处理入口,使用php-fpm进行管理
fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} location ~ .*\.(gif|jgp|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';
#access_log /var/log/nginx/access.log access;
}

如此,你便可访问 www.demo.com www.deom2.com www.demo3.com 了!

如果在正式的生产环境的话,则需要你的DNS服务器指定到你所在的服务器IP了。

ubuntu 13.04 nginx.conf 配置详解的更多相关文章

  1. nginx.conf配置详解

    ######Nginx配置文件nginx.conf中文详解##### #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_ ...

  2. nginx.conf 配置详解

    目录 pid user error_log worker_connections include http server nginx主配置文件中的内容 pid 主线程id的存储位置. # cat /u ...

  3. Nginx的配置文件nginx.conf配置详解

    user nginx nginx; #Nginx用户及组:用户 组.window下不指定 worker_processes 8; #工作进程:数目.根据硬件调整,通常等于CPU数量或者2倍于CPU. ...

  4. Nginx_配置文件nginx.conf配置详解

    user nginx nginx ; # Nginx用户及组:用户 组.window下不指定 worker_processes 8; # 工作进程:数目.根据硬件调整,通常等于CPU数量或者2倍于CP ...

  5. Nginx安全相关配置和nginx.conf中文详解

    一.centos下redis安全相关 1.背景 在使用云服务器时,如果我们的redis关闭了protected-mode模式,被病毒攻击的可能会大大增加,因此我们使用redis时候,最好更改默认端口, ...

  6. Nginx 核心配置详解

    目录 Nginx 核心配置详解 Nginx 四层访问控制: Nginx账户认证功能: 自定义错误页面: 自定义访问日志: 检测文件是否存在: 长连接配置: 作为下载服务器配置: 作为上传服务器: 其他 ...

  7. Nginx配置文件nginx.conf中文详解(转)

    ######Nginx配置文件nginx.conf中文详解##### #定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_ ...

  8. Windows XP硬盘安装Ubuntu 12.04双系统图文详解

    Windows XP硬盘安装Ubuntu 12.04双系统图文详解 Ubuntu 12.04 LTS版本于2012年4月26日发布,趁着五一放假,赶紧在自己的Windows XP的电脑上安装下Ubun ...

  9. Nginx配置文件nginx.conf中文详解【转】

    PS:Nginx使用有两三年了,现在经常碰到有新用户问一些很基本的问题,我也没时间一一回答,今天下午花了点时间,结合自己的使用经验,把Nginx的主要配置参数说明分享一下,也参考了一些网络的内容,这篇 ...

随机推荐

  1. python安装新版本及pip

    Linux安装python: yum install zlib -yyum install zlib-devel -y yum install readline-devel -y yum instal ...

  2. 局域网内的机器不能ping通虚拟机,但是虚拟机可以ping通局域网的机器

    将虚拟机的网络网络适配器模式改成桥接模式即可: 一.选择虚拟机里面的设置: 二.在虚拟机设置界面将网络适配器模式改成桥接模式

  3. Entity Framework应用:根据实体的EntityState状态实现增删改查

    在上一篇文章中,我们讲解了使用EF实现简单的增删改成,在这篇文章中我们使用实体的EntityState状态来优化数据的增删改查. 一.修改数据 上篇文章中的修改数据的方法是EF官方推荐的方式,即先查询 ...

  4. substance新版及问题

    新版地址:https://github.com/Insubstantial,目前是7.3版 http://stackoverflow.com/questions/3657538/substance-u ...

  5. PHP 实战之设计模式:PHP 中的设计模式

    本文主要讨论下Web开发中,准确而言,是PHP开发中的相关的设计模式及其应用.有经验的开发者肯定对于设计模式非常熟悉,但是本文主要是针对那 些初级的开发者.首先我们要搞清楚到底什么是设计模式,设计模式 ...

  6. Linux系统下邮件服务器的搭建(Postfix+Dovecot)

    对于网站来说,发送各种例如注册通知的邮件是很基本的一个需求,之前我一直用的是腾讯的企业邮箱,感觉挺方便的,直接可以绑定QQ邮箱接收邮件,网站配置一下SMTP也就可以发出邮件. 但是在前几天由于有重要信 ...

  7. PinnedListView分析二

    在PinnedListView分析一中还有一些细节在本文做一个补充,主要是view的绘制: 一个view在真正被绘制都是通过canvas来做,在ViewGroup内的z子view,一般再次此之前,还需 ...

  8. Python中的高级turtle(海龟)作图(续)

    四.填色 color 函数有三个参数.第一个参数指定有多少红色,第二个指定有多少绿色,第三个指定有多少蓝色.比如,要得到车子的亮红色,我们用 color(1,0,0),也就是让海龟用百分之百的红色画笔 ...

  9. 第三百四十四节,Python分布式爬虫打造搜索引擎Scrapy精讲—craw母版l创建自动爬虫文件—以及 scrapy item loader机制

    第三百四十四节,Python分布式爬虫打造搜索引擎Scrapy精讲—craw母版l创建自动爬虫文件—以及 scrapy item loader机制 用命令创建自动爬虫文件 创建爬虫文件是根据scrap ...

  10. 正则表达式-----------------------------------C#的正则表达式

    为了避免以后这样的情况,在此记录下正则表达式的一些基本使用方法附带小的实例.让以后在使用时能一目了然知道他的使用,为开发节约时间,同时也分享给大家 正则元字符 在说正则表达式之前我们先来看看通配符,我 ...