Nginx与www和没有www

前端之家收集整理的这篇文章主要介绍了Nginx与www和没有www前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个使用Nginx的服务器指令:

@H_404_5@ server { listen 80; server_name mydomain.net; root /home/sites/mydomain.net; location ~ \.PHP${ fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /home/sites/mydomain.net$fastcgi_script_name; fastcgi_index index.PHP; } }

当我访问mydomain.net时,这很有用.但是,如果用户尝试www.mydomain.net,那么这里没有任何内容可以应用这些内容

我所做的搜索显示人们有一个完整的其他指令用server_name www.mydomain.net监听,这似乎……不是很好.例如

@H_404_5@server { listen 80; server_name www.mydomain.net; root /home/sites/mydomain.net; location ~ \.PHP${ fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /home/sites/mydomain.net$fastcgi_script_name; fastcgi_index index.PHP; } }

基本上加倍配置代码.或者以其他方式进行重写.

这样做有一个较小的方法吗?

最佳答案
您可以在server_name中使用多个名称,甚至可以重复它.

例如,要回答三个主机名,您可以执行以下操作:

@H_404_5@server { server_name example.com www.example.com; server_name api.example.com;

猜你在找的Nginx相关文章