Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample nginx config for serving a rails API and static frontend like Ember on the same domain...
daemon off;
worker_processes 4;
events {
use epoll;
accept_mutex on;
multi_accept on;
worker_connections 1024;
}
http {
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_comp_level 2;
gzip_min_length 512;
gzip_proxied any;
gzip_vary on;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
server_tokens off;
tcp_nopush on;
tcp_nodelay on;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log;
include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
resolver NGINX_RESOLVER;
resolver_timeout 5s;
server {
server_name _;
listen 80;
keepalive_timeout 5;
root /var/www;
index index.html;
port_in_redirect off;
# client_max_body_size <%= ENV["CLIENT_MAX_BODY_SIZE"] %>;
location ~ ^/(api|oauth)/ {
# Use a variable so that nginx keeps resolving the hostname
set $backend "backend.example.com";
proxy_pass http://$backend:3000;
proxy_set_header Real-IP $remote_addr;
proxy_set_header Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header NginX-Proxy true;
proxy_ssl_session_reuse off;
proxy_redirect off;
}
location ~* \index.html$ {
expires -1;
}
location ~* \.(ogg|ogv|svgz|mp4|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|html|txt|htm)$ {
expires max;
log_not_found off;
access_log off;
add_header Cache-Control public;
fastcgi_hide_header Set-Cookie;
}
location ~* \.(eot|oft|svg|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
expires max;
log_not_found off;
access_log off;
add_header Cache-Control public;
fastcgi_hide_header Set-Cookie;
}
location ~ /\. {
deny all;
}
location / {
expires -1;
try_files $uri $uri/ /index.html =404;
}
}
}
@kunKun-tx

This comment has been minimized.

Show comment
Hide comment
@kunKun-tx

kunKun-tx May 30, 2018

it's about time to change application/x-javascript to application/javascript.

kunKun-tx commented May 30, 2018

it's about time to change application/x-javascript to application/javascript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment