nginx綁定多個域名


nginx綁定多個域名涉及到的技術為url rewrite,可以先了解下知識背景再過來學習。

這里以域名:www.sample.com為例

1.在/usr/local/nginx/conf文件夾中創建sample.conf文件

2.在其中寫入如下內容並保存:

server{        
        listen 80;
                server_name sample.cn www.sample.cn;
                root /home/www/sample;
		index index.html index.htm;
                charset utf-8;
                location / {
			root /home/www/sample;
                        index index.html index.htm;
                }
            
                location ~* \.(jpg|gif|png)$ {
  			if (-f $request_filename) {
				expires max;
				break;
			}
		}
		location ~ /\.ht {
                        deny all;
                }
}

3.然后打開nginx.conf文件,在最后一行追加如下內容:

    include linkcp.conf;

4.創建/home/www/sample文件夾,並在其中創建文件index.html內容如下

<html>
<head>
</head>
<body>
<p>Test Page!</p>
</body>
</html>

5.在瀏覽器中輸入域名www.sample.com顯示如下:

Test Page! 

 

配置完成


免責聲明!

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



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