Skip to content

Instantly share code, notes, and snippets.

@bingxie
Last active August 29, 2015 14:11
Show Gist options
  • Save bingxie/a0039781a52ad908b0a2 to your computer and use it in GitHub Desktop.
Save bingxie/a0039781a52ad908b0a2 to your computer and use it in GitHub Desktop.
Nginx的配置
# nginx.conf
http {
client_max_body_size 20M; #上传文件的大小
}
------------------------------------------------------------------------------------
#Nginx应用配置
upstream app-name {
# 配置unicorn服务器器
server unix:/opt/app-name/tmp/sockets/unicorn.sock
# 设置为0意味着,nginx总是重试upstream,即使这个upstream不能响应一个正常的HTTP请求。
# (例如:有时unicorn的master会干掉超时的工作进程)
fail_timeout=0;
}
server {
listen 80;
# 域名
server_name app-name.com;
server_tokens off;
keepalive_timeout 5;
# 由于在AWS的loadbalancer上设置的SSH,所有的http请求都会跳转成https
if ($http_x_forwarded_proto = "http") {
return 301 https://app-name.com$request_uri;
}
location ~ /\. {
# 可以设置nginx的日志文件
access_log off;
log_not_found off;
deny all;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app-name;
# 让nginx来处理400以上的错误页面,然后转到error_page模块处理
proxy_intercept_errors on;
}
# 自定义的404错误页面
error_page 404 /404.html;
location = /404.html {
root /opt/app-name/current/public;
}
# 自定义的502错误页面
error_page 502 /502.html;
location = /502.html {
root /opt/app-name/current/public;
}
# nginx直接响应静态文件
location ~ ^/(assets)/ {
root /opt/app_name/current/public;
gzip_static on;
# add_header Last-Modified "";
# add_header ETag "";
expires max;
add_header Cache-Control public;
}
}
@bingxie
Copy link
Author

bingxie commented Dec 22, 2014

Tip:
修改配置后,使用nginx configtest 来测试修改的配置是否有问题
然后可以重新载入配置文件: nginx reload

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