红联Linux门户
Linux帮助

linux同一个ip绑定两个不同的域名访问两个不同的项目

发布时间:2017-03-23 15:48:26来源:linux网站作者:linux人
用两个不同的域名绑定同一个ip访问两个不同的项目是完全可以做到的,远没有想象的那么复杂,使用服务器环境LNMP。
 
要实现这个功能首先需要配置nginx,打开nginx的配置文档(nginx.conf)
 
server {
listen 80;          //端口
server_name www.xxxxx.com;      //域名
access_log xxxxx;      //日志存储的位置
root xxxxx;  //项目根路径
index index.html index.htm index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /nginx_status {
stub_status on;
access_log off;
allow xxx.xxx.xx.xx;
deny all;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}
 
以上只是一个项目的配置,同样的我们想同一个服务器打在两个不同的项目那么所需要做的就是复制相同的一份代码,指定不同的项目路径。
 
server {
listen 80;    //端口
server_name www.xxxx.com;    //域名
access_log /data/wwwlogs/access_nginx.log combined;
root xxxxxxx;    //项目根路径
index index.html index.htm index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}
 
要想实现这个功能的中心就在于域名的不同和项目根路径的不同。
 
本文永久更新地址:http://www.linuxdiyf.com/linux/29422.html