用兩個不同的域名綁定同一個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;
}
}
要想實現這個功能的中心就在於域名的不同和項目根路徑的不同