Last active
February 16, 2024 13:02
-
-
Save Max95Cohen/6c0423b30474863a4432decc110d9954 to your computer and use it in GitHub Desktop.
example.conf nginx virtual host config
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
map $http_origin $allow_origin { | |
~^https?://(.*\.)?my-domain.com(:\d+)?$ $http_origin; | |
default ""; | |
} | |
upstream websocket { | |
server localhost:3001; | |
} | |
server { | |
listen 443 ssl; | |
server_name example.com www.example.com; | |
index index.php index.html; | |
root /var/www/example.com; | |
add_header X-Frame-Options "SAMEORIGIN"; | |
add_header X-Content-Type-Options "nosniff"; | |
add_header Access-Control-Allow-Origin $allow_origin always; | |
add_header Access-Control-Allow-Credentials true; | |
add_header Access-Control-Allow-Methods 'GET, PATCH, POST, OPTIONS, PUT, DELETE'; | |
add_header Access-Control-Allow-Headers *; | |
charset utf-8; | |
location / { | |
proxy_pass http://localhost:8080; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto $scheme; | |
} | |
location / { | |
try_files $uri $uri/ =404; | |
} | |
location ~ \.php$ { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; | |
} | |
location ~ \.php$ { | |
fastcgi_pass 127.0.0.1:9074; | |
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
location ~ /\.(?!well-known).* { | |
deny all; | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
location = /favicon.ico { | |
access_log off; | |
log_not_found off; | |
} | |
location = /robots.txt { | |
access_log off; | |
log_not_found off; | |
} | |
location ^~ /socket/ { | |
proxy_pass http://websocket; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
} | |
error_page 404 /index.php; | |
ssl_certificate /path/certificate.crt; | |
ssl_certificate_key /path/privet.key; | |
} | |
server { | |
listen 80; | |
server_name example.com; | |
if ($host = example.com) { | |
return 301 https://$host$request_uri; | |
} | |
return 404; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment