Skip to content

Instantly share code, notes, and snippets.

@richardcalahan
Created March 9, 2022 13:31
Show Gist options
  • Save richardcalahan/5eb372618f69f7c8e3220a99bc70e017 to your computer and use it in GitHub Desktop.
Save richardcalahan/5eb372618f69f7c8e3220a99bc70e017 to your computer and use it in GitHub Desktop.
Craft CMS - NGINX
server {
listen 80;
server_name api.commoncitizen.test;
return 301 https://api.commoncitizen.test$request_uri;
}
server {
listen 80;
server_name cms.commoncitizen.test;
return 301 https://cms.commoncitizen.test$request_uri;
}
server {
listen 443 ssl;
ssl_certificate ssl/_wildcard.commoncitizen.test.pem;
ssl_certificate_key ssl/_wildcard.commoncitizen.test-key.pem;
index index.php index.html index.htm;
server_name api.commoncitizen.test cms.commoncitizen.test;
if ( $host ~ 'cms' ) {
set $root 'cms';
}
if ( $host ~ 'api' ) {
set $root 'api';
}
root [PATH/TO/PROJECT]/craft/$root;
client_max_body_size 30m;
location / {
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^(.*) /index.php?p=$1 last;
}
error_page 404 /404.html;error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PATCH, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization';
add_header 'Access-Control-Allow-Credentials' true;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment