改进Nginx服务器块文件

分享于 

1分钟阅读

互联网

  繁體

问题:

如何改进以下server block文件


server {


 listen 80;


 return 301 https://$host$request_uri;


}



server {


 listen 443 ssl;



 ssl_certificate /etc/letsencrypt/live/demo.com/fullchain.pem;


 ssl_certificate_key /etc/letsencrypt/live/demo.com/privkey.pem;


 include /etc/letsencrypt/options-ssl-nginx.conf;


 ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;



 server_name demo.com www.demo.com;



 root /var/www/demo.com/public;



 access_log /var/log/nginx/demo-com.access.log;


 error_log /var/log/nginx/demo-com.error.log;



 index index.php index.html index.htm index.nginx-debian.html;



 location / {


 try_files $uri $uri/ /index.php?$query_string;


 }



 location ~ .php$ {


 include snippets/fastcgi-php.conf;



 fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;


 }



 location ~ /.ht {


 deny all;


 }


}



为了防止警告nginx: [warn] conflicting server name "" on 0.0.0.0:80, ignored 在运行命令sudo nginx -t时显示。


答案1:

应该在每个server块中定义server_name



文件  Server  IMP  Block  Nginx  
相关文章