博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
多站点配置
阅读量:7210 次
发布时间:2019-06-29

本文共 2645 字,大约阅读时间需要 8 分钟。

hot3.png

当我们有了一个域名,有了一个服务器后,如果我们的服务器只用来运行一个网站之类的程序的话,太浪费了,为了合理的利用其云服务器这个资源,我们可以用它存放和运行多个程序,比如说多个网站

那怎样才能让一个域名,一个服务器运行多个网站呢?

其实就是多站点问题,我们配置一下,就可以了

首先,我的服务器是CentOS6.5,运行LNMP(linux,Nginx,Mysql,php)环境,配置多站点,我们就只需要做两个操作

1.  去域名管理添加解析记录

2.  配置一下nginx的配置文件

我们打开nginx的nginx.conf文件  (一般在 /usr/local/nginx/conf 下)

假设我们有两个子域名:demo1.site.com、demo2.site.com

那我们在nginx.conf下只需这样配置即可

server {    listen 80;    server_name demo1.site.com;    access_log /data/wwwlogs/access_nginx.log combined;    root /data/wwwroot/default/demo1;    index index.php index.html index.htm;    #error_page 404 /404.html;    #error_page 502 /502.html;    location /nginx_status {      stub_status on;      access_log off;      allow 127.0.0.1;      deny all;    }    location / {      #try_files $uri $uri/ /index.php?$query_string;       if (!-e $request_filename){          rewrite ^/(.*)$ /index.php/$1 last;     }    }    location ~ [^/]\.php(/|$) {      #fastcgi_pass remote_php_ip:9000;      fastcgi_split_path_info ^(.+\.php)(/.+)$;      fastcgi_pass unix:/dev/shm/php-cgi.sock;      fastcgi_index index.php;      include fastcgi.conf;      fastcgi_param   PATH_INFO   $fastcgi_path_info;        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;    }    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {      expires 30d;      access_log off;    }    location ~ .*\.(js|css)?$ {      expires 7d;      access_log off;    }    location ~ /\.ht {      deny all;    } }server {    listen 80;    server_name demo2.site.com;    access_log /data/wwwlogs/access_nginx.log combined;    root /data/wwwroot/default/demo2;    index index.php index.html index.htm;    #error_page 404 /404.html;    #error_page 502 /502.html;    location /nginx_status {      stub_status on;      access_log off;      allow 127.0.0.1;      deny all;    }    location / {      #try_files $uri $uri/ /index.php?$query_string;       if (!-e $request_filename){          rewrite ^/(.*)$ /index.php/$1 last;     }    }    location ~ [^/]\.php(/|$) {      #fastcgi_pass remote_php_ip:9000;      fastcgi_split_path_info ^(.+\.php)(/.+)$;      fastcgi_pass unix:/dev/shm/php-cgi.sock;      fastcgi_index index.php;      include fastcgi.conf;      fastcgi_param   PATH_INFO   $fastcgi_path_info;        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;    }    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {      expires 30d;      access_log off;    }    location ~ .*\.(js|css)?$ {      expires 7d;      access_log off;    }    location ~ /\.ht {      deny all;    } }

 

当然,通过vhost文件也可以配置,但是各有好处吧,本人比较习惯使用这种方式

重启nginx,就可以看到效果了

 

转载于:https://my.oschina.net/9264736/blog/1813151

你可能感兴趣的文章
微信支付中的刷卡支付和扫码支付测试
查看>>
中国金融出版社出版的2013版《风险管理》
查看>>
BZOJ1055: [HAOI2008]玩具取名[区间DP]
查看>>
【转】iOS 10 UserNotifications 使用说明
查看>>
英文投稿模板
查看>>
计算机网络常见英文缩写
查看>>
Esper epl语句实验
查看>>
使用phpize建立php扩展(Cannot find config.m4)
查看>>
【TensorFlow】CNN
查看>>
redis cli命令
查看>>
C#中委托和事件的区别
查看>>
数据库操作
查看>>
CLIPS
查看>>
HBase中数据的多版本特性潜在的意外
查看>>
僵还是老的la,看myeclipse的spring mvc3 scaffolding 完胜sts
查看>>
网上开店进货渠道大参考
查看>>
经典语录
查看>>
【配置文件】log4j是什么log4j
查看>>
xsd验证允许空值
查看>>
图灵成立七周年——经典回顾
查看>>