nginx配置多个站点共用80端口,不算端口冲突吗?-灵析社区

无敌美少女

就是在做php项目的时候,自己本地有多个web项目,对应也是配置了nginx的配置,比如A项目: server { listen 80; server_name www.aa.com; root /WWW/api-aa; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { log_not_found off; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 项目B配置如下: server { listen 80; server_name www.bb.com; root /WWW/api-bb; index index.html index.htm index.php; location / { try_files $uri $uri/ /index.php?$query_string; } location = /favicon.ico { log_not_found off; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 就是上面2个项目都是80端口,也都是正常运行,那为什么2个项目都使用80端口但是不算端口冲突呢?

阅读量:16

点赞量:0

问AI
你可以想象一下,你有一个邮局,这个邮局只有一个信箱(这个信箱就像服务器上的80端口)。现在,你负责处理两个不同的地方的信件,一个是“A镇”,另一个是“B村”。 每封信件都会写明是发给“A镇”还是“B村”的。所以,就算所有的信都投到同一个信箱(80端口)里,邮局工作人员(就像Nginx服务器)也可以通过查看信件上的地址(这就是server_name,比如 www.aa.com 或 www.bb.com),然后把信分别送到“A镇”或“B村”。 "企业微信截图_17023627641101.png" (https://wmlx-new-image.oss-cn-shanghai.aliyuncs.com/images/20241101/45824eadc322102159f596d0533b11af.png)