Skip to content

Instantly share code, notes, and snippets.

@Jpuelpan
Last active October 18, 2015 22:01
Show Gist options
  • Save Jpuelpan/f9f738855756435e44de to your computer and use it in GitHub Desktop.
Save Jpuelpan/f9f738855756435e44de to your computer and use it in GitHub Desktop.
Configurations for NGINX
# Listen on port
server {
listen 80;
server_name my.domain.com;
location ~ ^/(assets)/ {
root /path/to/project/public;
# gzip_static on;
# expires max;
# add_header Cache-Control public;
# access_log /dev/null;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3000;
}
}
# For PHPMyadmin
server {
...
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
...
}
# Some app with PHP FPM
server{
listen 80;
server_name mydomain.com;
location / {
root /path/to/app;
index index.php index.htm index.html;
location ~ ^(.+\.php)$ {
try_files $uri =404;
root /path/to/app/;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
}
# Some app with SSL
server {
listen 443;
server_name mydomain.com;
ssl on;
ssl_certificate /etc/ssl/certs/cert.crt;
ssl_certificate_key /etc/ssl/private/key.key;
rewrite ^/$ /share;
location / {
root /path/to/the/application;
proxy_pass https://localhost:8443;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header host $host;
proxy_set_header X-Forwarded-Server $host;
}
}
# For an Unicorn or Gunicorn application
upstream application {
server unix:/home/appmanager/application/tmp/application.sock;
}
server {
listen 80;
server_name *.application.com;
root /home/appmanager/application/public;
location / {
try_files $uri @application;
}
location @application {
proxy_pass http://application;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment