Merge pull request 'Handles domain that is not explicitly configured' (#1) from nginx-default-server into master
Reviewed-on: marito/Lenvi#1 - Tested on WSL2 Ubuntu 24.04: functions as expected. Domains listed in the hosts file but not configured in Nginx correctly return a 404 error.
This commit is contained in:
		
						commit
						ad23896e5f
					
				
							
								
								
									
										11
									
								
								roles/nginx/files/00-default-catch-all.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								roles/nginx/files/00-default-catch-all.conf
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
# This is the default catch-all server.
 | 
			
		||||
# It handles any request for a domain that is not explicitly configured.
 | 
			
		||||
server {
 | 
			
		||||
    listen 80 default_server;
 | 
			
		||||
    listen [::]:80 default_server;
 | 
			
		||||
 | 
			
		||||
    server_name _;
 | 
			
		||||
 | 
			
		||||
    # Return a 404 Not Found error.
 | 
			
		||||
    return 404;
 | 
			
		||||
}
 | 
			
		||||
@ -14,4 +14,13 @@
 | 
			
		||||
  ansible.builtin.file:
 | 
			
		||||
    path: /etc/nginx/sites-enabled/default
 | 
			
		||||
    state: absent
 | 
			
		||||
  notify: Reload Nginx
 | 
			
		||||
 | 
			
		||||
- name: "Create a default catch-all server block"
 | 
			
		||||
  ansible.builtin.copy:
 | 
			
		||||
    src: 00-default-catch-all.conf
 | 
			
		||||
    dest: /etc/nginx/conf.d/00-default-catch-all.conf
 | 
			
		||||
    owner: root
 | 
			
		||||
    group: root
 | 
			
		||||
    mode: '0644'
 | 
			
		||||
  notify: Reload Nginx
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user