linux 同一個ip 綁定兩個不同的域名 訪問兩個不同的項目


 用兩個不同的域名綁定同一個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;
}
}

要想實現這個功能的中心就在於域名的不同和項目根路徑的不同


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM