linux 同一個(gè)ip 綁定兩個(gè)不同的域名 訪問(wèn)兩個(gè)不同的項(xiàng)目
時(shí)間:2023-02-01 08:20:01 | 來(lái)源:建站知識(shí)
時(shí)間:2023-02-01 08:20:01 來(lái)源:建站知識(shí)
phubing 2020-01-08 11:52:17
267
收藏
分類專欄: Nginx 文章標(biāo)簽: Nginx 域名 IP
版權(quán)
用兩個(gè)不同的域名綁定同一個(gè)ip訪問(wèn)兩個(gè)不同的項(xiàng)目是完全可以做到的,遠(yuǎn)沒(méi)有想象的那么復(fù)雜,使用服務(wù)器環(huán)境LNMP
要實(shí)現(xiàn)這個(gè)功能首先需要配置nginx
打開(kāi)nginx的配置文檔(nginx.conf)
server {
listen 80; //端口
server_name www.xxxxx.com; //域名
access_log xxxxx; //日志存儲(chǔ)的位置
root xxxxx; //項(xiàng)目根路徑
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;
}
}
以上只是一個(gè)項(xiàng)目的配置,同樣的我們想同一個(gè)服務(wù)器打在兩個(gè)不同的項(xiàng)目那么所需要做的就是復(fù)制相同的一份代碼,指定不同的項(xiàng)目路徑
server {
listen 80; //端口
server_name www.xxxx.com; //域名
access_log /data/wwwlogs/access_nginx.log combined;
root xxxxxxx; //項(xiàng)目根路徑
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;
}
}
要想實(shí)現(xiàn)這個(gè)功能的中心就在于域名的不同和項(xiàng)目根路徑的不同
關(guān)鍵詞:訪問(wèn),項(xiàng)目,同一