Nginx 设置,设置已经解析的域名,在nginx中没有定义相应server时的默认访问
生活随笔
收集整理的這篇文章主要介紹了
Nginx 设置,设置已经解析的域名,在nginx中没有定义相应server时的默认访问
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
場景介紹:
因為業務需求,我們需要對域名進行解析,這里我對域名進行了如下解析
但是,因為業務需求,我可能在nginx中只定義了kuman.xiaobudiu.top 和 www.xiaobudiu.top 的相應server的子配置文件,如圖
那么問題來了,怎么才能讓其余已經解析的域名訪問時,不會出現空白或是報錯頁面呢
這時,我們就需要應用到一個參數default_server,讓所有已經解析,但是在nginx中沒有對應server配置的域名默認訪問到我們設置的帶default_server參數的server。
配置文件示例:
server { listen 80 default_server; server_name www.xiaobudiu.top; charset utf-8; error_log /etc/nginx/logs/error/www.xiaobudiu.top.log error; access_log /etc/nginx/logs/access/www.xiaobudiu.top.log main; root /data/www; index index.html index.htm index.php; location /favicon.ico { log_not_found off; access_log off; }location ~ \.php$ { fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }location ~ /\.ht { deny all; }}這樣,當我訪問www.xiaobudiu.top 和kuman.xiaobudiu.top 時,就會訪問到對應server設置的路徑,而訪問test.xiaobudiu.top 和 test.up.xiaobudiu.top域名時,就會默認訪問www.xiaobudiu.top網站
總結
以上是生活随笔為你收集整理的Nginx 设置,设置已经解析的域名,在nginx中没有定义相应server时的默认访问的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx 网站定义自己的错误页面
- 下一篇: Nginx使用upstream实现动静分