Last active
August 11, 2024 21:43
-
-
Save guifsdev/e91431990c3492d5ddfbd73ca0dbcacb to your computer and use it in GitHub Desktop.
This Nginx configuration file sets up an HTTPS server for mydomain.com, handles general web requests, and includes specific configurations for security headers, PHP processing, and WebSocket proxying
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen [::]:443 ssl ipv6only=on; # managed by Certbot | |
listen 443 ssl; # managed by Certbot | |
server_name www.mydomain.com; | |
ssl_certificate /etc/letsencrypt/live/www.mydomain.com/fullchain.pem; # managed by Certbot | |
ssl_certificate_key /etc/letsencrypt/live/www.mydomain.com/privkey.pem; # managed by Certbot | |
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot | |
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot | |
# Redirect non-www to www | |
if ($host = 'mydomain.com') { | |
return 301 https://www.mydomain.com$request_uri; | |
} | |
root /srv/admin/public; | |
add_header X-Frame-Options "SAMEORIGIN"; | |
add_header X-XSS-Protection "1; mode=block"; | |
add_header X-Content-Type-Options "nosniff"; | |
index index.php; | |
charset utf-8; | |
# General web application handling | |
location / { | |
try_files $uri $uri/ /index.php?$query_string; | |
} | |
# WebSocket handling (if WebSocket routes are specific) | |
location /app/ { | |
proxy_pass https://mydomain.com:6001; | |
proxy_read_timeout 60; | |
proxy_connect_timeout 60; | |
proxy_redirect off; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection 'upgrade'; | |
proxy_set_header Host $host; | |
proxy_cache_bypass $http_upgrade; | |
} | |
location = /favicon.ico { access_log off; log_not_found off; } | |
location = /robots.txt { access_log off; log_not_found off; } | |
error_page 404 /index.php; | |
location ~ \.php$ { | |
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; | |
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
location ~ /\.(?!well-known).* { | |
deny all; | |
} | |
} | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name mydomain.com www.mydomain.com; | |
return 301 https://www.mydomain.com$request_uri; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment