阿里云nginx服务器多站点的配置

阿里云nginx服务器多站点的配置

标签: nginx阿里云服务器
1736人阅读 评论(0) 收藏 举报
本文章已收录于:
分类:

阿里云nginx服务器多站点的配置

今天配置了一下多站点,记录一下配置的过程...
  1. 首先要找到nginx 配置文件之所在,阿里云上的nginx.conf 文件上 /alidata/server/nginx-1.4.4/conf 中。
  2. 然后在conf目录下创建一个vhosts 目录,  这个目录是用来存放不同站点的配置文件的。
  3. 然后呢, 在nginx.conf 最后 加入一行 include /alidata/server/nginx/conf/vhosts/*.conf;
    1. user  www www;  
    2. worker_processes  1;  
    3.   
    4. error_log  /alidata/log/nginx/error.log crit;  
    5. pid        /alidata/server/nginx/logs/nginx.pid;  
    6.   
    7. #Specifies the value for maximum file descriptors that can be opened by this process.   
    8. worker_rlimit_nofile 65535;  
    9.   
    10. events   
    11. {  
    12.   use epoll;  
    13.   worker_connections 65535;  
    14. }  
    15.   
    16.   
    17. http {  
    18.     include       mime.types;  
    19.     default_type  application/octet-stream;  
    20.   
    21.     #charset  gb2312;  
    22.   
    23.     server_names_hash_bucket_size 128;  
    24.     client_header_buffer_size 32k;  
    25.     large_client_header_buffers 4 32k;  
    26.     client_max_body_size 8m;  
    27.   
    28.     sendfile on;  
    29.     tcp_nopush     on;  
    30.   
    31.     keepalive_timeout 60;  
    32.   
    33.     tcp_nodelay on;  
    34.   
    35.     fastcgi_connect_timeout 300;  
    36.     fastcgi_send_timeout 300;  
    37.     fastcgi_read_timeout 300;  
    38.     fastcgi_buffer_size 64k;  
    39.     fastcgi_buffers 4 64k;  
    40.     fastcgi_busy_buffers_size 128k;  
    41.     fastcgi_temp_file_write_size 128k;  
    42.   
    43.     gzip on;  
    44.     gzip_min_length  1k;  
    45.     gzip_buffers     4 16k;  
    46.     gzip_http_version 1.0;  
    47.     gzip_comp_level 2;  
    48.     gzip_types       text/plain application/x-javascript text/css application/xml;  
    49.     gzip_vary on;  
    50.     #limit_zone  crawler  $binary_remote_addr  10m;  
    51.     log_format '$remote_addr - $remote_user [$time_local] "$request" '  
    52.                   '$status $body_bytes_sent "$http_referer" '  
    53.                   '"$http_user_agent" "$http_x_forwarded_for"';  
    54.                     
    55.     # 加入下面一行 表示将 vhosts 下面所有的 conf 文件包含进来  
    56.     include /alidata/server/nginx/conf/vhosts/*.conf;  
    57. }  
    user  www www;
    worker_processes  1;
    
    error_log  /alidata/log/nginx/error.log crit;
    pid        /alidata/server/nginx/logs/nginx.pid;
    
    #Specifies the value for maximum file descriptors that can be opened by this process. 
    worker_rlimit_nofile 65535;
    
    events 
    {
      use epoll;
      worker_connections 65535;
    }
    
    
    http {
    	include       mime.types;
    	default_type  application/octet-stream;
    
    	#charset  gb2312;
    
    	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 60;
    
    	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;
    	#limit_zone  crawler  $binary_remote_addr  10m;
    	log_format '$remote_addr - $remote_user [$time_local] "$request" '
    	              '$status $body_bytes_sent "$http_referer" '
    	              '"$http_user_agent" "$http_x_forwarded_for"';
    	              
    	# 加入下面一行 表示将 vhosts 下面所有的 conf 文件包含进来
    	include /alidata/server/nginx/conf/vhosts/*.conf;
    }
  4. 然后,就是在vhosts 目录下写 你对应站点的 conf 文件了。下面给出一个范例
    1. server {  
    2.     listen       80;  
    3.     # 这个表示 网站域名, 可以是二级甚至多级域名  
    4.     server_name  localhost demo.com www.demo.com test.demo.com;  
    5.   
    6.     # 表示默认索引文件  
    7.     index index.html index.htm index.php;  
    8.       
    9.     # 该站点对应的网站根目录所在  
    10.     root /alidata/www/demo;  
    11.   
    12.     location ~ .*\.(php|php5)?$  
    13.     {  
    14.         #fastcgi_pass  unix:/tmp/php-cgi.sock;  
    15.         fastcgi_pass  127.0.0.1:9000;  
    16.         fastcgi_index index.php;  
    17.         include fastcgi.conf;  
    18.     }  
    19.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$  
    20.     {  
    21.         expires 30d;  
    22.     }  
    23.     location ~ .*\.(js|css)?$  
    24.     {  
    25.         expires 1h;  
    26.     }  
    27.   
    28.     # 伪静态规则  
    29.     include /alidata/server/nginx/conf/rewrite/phpwind.conf;  
    30.     access_log  /alidata/log/nginx/access/phpwind.log;  
    31. }  
    server {
        listen       80;
        # 这个表示 网站域名, 可以是二级甚至多级域名
        server_name  localhost demo.com www.demo.com test.demo.com;
    
        # 表示默认索引文件
        index index.html index.htm index.php;
        
        # 该站点对应的网站根目录所在
        root /alidata/www/demo;
    
        location ~ .*\.(php|php5)?$
        {
            #fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires 30d;
        }
        location ~ .*\.(js|css)?$
        {
            expires 1h;
        }
    
        # 伪静态规则
        include /alidata/server/nginx/conf/rewrite/phpwind.conf;
        access_log  /alidata/log/nginx/access/phpwind.log;
    }
  5. 如果还要继续添加, 直接复制文件。然后修改一下 server_name, root, 和access_log(如果有必要的话) 就OK了。
  6. 然后,不要立马重启nginx,应该要先测试一下nginx 配置文件是否正常. 找到nginx 的 sbin目录。 注意, 这个地方是nginx 的sbin 目录(这个目录与nginx 的conf 目录是同级目录)。linux 下有许多与sbin同名的目录。 容易搞错。 在阿里云服务器上一般默认的目录是 /alidata/server/nginx-1.4.4/sbin。
  7. 输入 cd /alidata/server/nginx-1.4.4/sbin,然后输入 ./nginx -t ,如果控制台显示下面两行,则表示配置成功了,否则请根据提示继续检查配置文件。
    nginx: the configuration file /alidata/server/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /alidata/server/nginx/conf/nginx.conf test is successful

  8. 配置成功之后, 就 需要重启 nginx 服务器。 在sbin目录下输入命令:./nginx -s reload, 然后整个过程就完成了。
另外, 总结一下nginx 的几个常用命令:
  1. 启动  
  2. ./nginx  
  3.   
  4. 重启  
  5. ./nginx -s reload  
  6.   
  7. 关闭  
  8. ps -ef | grep nginx     # 查询nginx主进程号  
  9. 从容停止   kill -QUIT 主进程号  
  10. 快速停止   kill -TERM 主进程号  
  11. 强制停止   kill -9 nginx  
  12. 若nginx.conf配置了pid文件路径,如果没有,则在logs目录下  
  13. kill -信号类型 '/usr/local/nginx/logs/nginx.pid'  
  14.   
  15. 判断配置文件是否正确  
  16. ./nginx -t  
启动
./nginx

重启
./nginx -s reload

关闭
ps -ef | grep nginx     # 查询nginx主进程号
从容停止   kill -QUIT 主进程号
快速停止   kill -TERM 主进程号
强制停止   kill -9 nginx
若nginx.conf配置了pid文件路径,如果没有,则在logs目录下
kill -信号类型 '/usr/local/nginx/logs/nginx.pid'

判断配置文件是否正确
./nginx -t
1
0
 
 
我的同类文章

参考知识库

img
JavaScript知识库

img
PHP知识库

img
Linux知识库

img
软件测试知识库

img
jQuery知识库

img
AngularJS知识库

更多资料请参考:
猜你在找
Nginx服务器入门
阿里云ECS Linux服务器项目部署实战视频课程
Nginx 高性能 WEB服务器系列
Nginx服务器配置
2017最新Linux集群全网服务器数据备份方案超细实战课
关闭
查看评论

  暂无评论

* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
  • 个人资料
    • 访问:159368次
    • 积分:4138
    • 等级:
      积分:4138
    • 排名:第6482名
    • 原创:231篇
    • 转载:10篇
    • 译文:0篇
    • 评论:28条
  • 最新评论
收藏助手

提问

您的问题将会被发布在“技术问答”频道 ×
该问题已存在,请勿重复提问
插入图片
| | | | | |
  
0 0 0:0
推荐标签:
我要悬赏
取消 发布
可能存在类似的问题:

保存代码片

整理和分享保存的代码片,请访问代码笔记
  • *标题
  • *描述
  •  标签
    nginxx 阿里云x 服务器x
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值