Nginx configure subdomain

Nginx configure subdomain

Http 服务器 3 months ago 368 0

I recently wrote a demo that requires a second-level domain name to display

Domain name server

My domain name uses a CDN, so I have to go to the CDN to configure it, for example 「cloudflare」

Record type CNAME, nameyour second-level domain name "book", contentyour domain name "yiqiao.me", after configuration, whether it can be accessed under ping.

Nginx Config

update Nginx Setting,Take the default file as an example

sudo vi /etc/nginx/sites-available/default

Since my project is written by the Laravel framework, my configuration file is as follows:

server {
    listen 80;
    server_name yiqiao.me;
    root Your project path/public;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
      try_files $uri /index.php =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/run/php/php7.2-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
    }
}

server {
    listen 80;
    server_name book.yiqiao.me;
    root Your project path/public;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~ \.php$ {
      try_files $uri /index.php =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/run/php/php7.2-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include fastcgi_params;
    }
}

After configuration, nginx -t, check if the NGINX configuration is correct, and restartservice nginx reload

原文: http://yiqiao.me/articles/24/nginx-pei-zhi-er-ji-yu-ming

版权声明: 自由转载-非商用-非衍生-保持署名 (创意共享3.0许可证)