Last active
February 6, 2021 04:26
-
-
Save 1Rogue/d831528c89ab4b93d437 to your computer and use it in GitHub Desktop.
nginx Site Templates
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
# https://gist.github.com/1Rogue/d831528c89ab4b93d437 | |
server { | |
listen 80; | |
server_name subdomain.*; | |
#substitute "codelanx" with hostname of choice | |
access_log /var/log/nginx/subdomain.codelanx.access.log; | |
error_log /var/log/nginx/subdomain.codelanx.error.log; | |
root /var/www/subdomain; | |
index index.php index.html index.htm; | |
location ~ \.php$ { | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_pass unix:/var/run/php7.0-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
} |
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
upstream jira { # example, service name will be "jira" and can be referenced as such | |
server localhost:8080; | |
} |
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
# https://gist.github.com/1Rogue/d831528c89ab4b93d437 | |
server { | |
listen 80 default_server; | |
#substitute "codelanx" with hostname of choice | |
access_log /var/log/nginx/codelanx.access.log; | |
error_log /var/log/nginx/codelanx.error.log; | |
root /var/www/root; | |
index index.php index.html index.htm; | |
error_page 404 /404.html; | |
error_page 500 502 503 504 /50x.html; | |
location = /404.html { | |
root /var/www/errors; | |
} | |
location = /50x.html { | |
root /var/www/errors; | |
} | |
location ~ \.php$ { | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_pass unix:/var/run/php7.0-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
} |
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
# https://gist.github.com/1Rogue/d831528c89ab4b93d437 | |
server { | |
listen 80; | |
server_name subdomain.*; | |
#substitute "codelanx" with hostname of choice | |
access_log /var/log/nginx/subdomain.codelanx.access.log; | |
error_log /var/log/nginx/subdomain.codelanx.error.log; | |
root /var/www/subdomain; | |
index index.php index.html index.htm; | |
location / { | |
root /var/www/subdomain; | |
try_files $uri /index.php; | |
} | |
location ~ \.php$ { | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_pass unix:/var/run/php7.0-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
} |
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
location ~ \.php$ { | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_pass unix:/var/run/php7.0-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} |
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 80; | |
server_name subdomain.*; | |
access_log /var/log/nginx/log/subdomain.codelanx.access.log; | |
error_log /var/log/nginx/log/subdomain.codelanx.error.log; | |
index index.html index.htm; | |
## send request back to upstream 'service' ## | |
location / { | |
proxy_pass http://service; | |
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; | |
proxy_redirect off; | |
proxy_buffering off; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
} |
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
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /var/www/errors; | |
} | |
error_page 404 /404.html; | |
location = /404.html { | |
root /var/www/errors; | |
} |
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
# https://gist.github.com/1Rogue/d831528c89ab4b93d437 | |
# Note I have not set up / tested this myself, as I have not needed SSL on my own thus far | |
server { | |
listen 80; | |
server_name localhost; | |
root html; | |
index index.html index.htm; | |
ssl on; | |
ssl_certificate cert.pem; | |
ssl_certificate_key cert.key; | |
ssl_session_timeout 5m; | |
ssl_protocols SSLv3 TLSv1; | |
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP; | |
ssl_prefer_server_ciphers on; | |
location / { | |
try_files $uri $uri/ =404; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that due to how this is mapped, the server's "web root" is located in
/var/www
for simplicity. In addition to this,/var/www/errors
and/var/www/root
are reserved for error pages and the root site, respectively.