nginx config example
来源:互联网 发布:park hyun seo 编辑:程序博客网 时间:2024/05/17 13:46
upstream lunaserver {
server localhost:3000;
server localhost:3001;
}
server {
listen 80;
server_name localhost;
root /www/luna-server/public;
# individual nginx logs for this lunas-erver vhost
access_log /var/lib/luna/log/luna-server_access.log;
error_log /var/lib/luna/log/luna-server_error.log;
location / {
try_files $uri @luna-server;
}
location @luna-server {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
client_max_body_size 360M;
client_body_buffer_size 5256K;
proxy_pass http://lunaserver;
}
#for monitorix
location /monitorix {
index index.html;
}
location ~ \.pl|cgi$ {
# try_files $uri =404;
gzip off;
fastcgi_pass 127.0.0.1:8999;
fastcgi_index index.pl;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Originating-IP $remote_addr;
proxy_set_header HTTP_REMOTE_ADDR $remote_addr;
proxy_set_header REMOTE_ADDR $remote_addr;
}
#for freeswtich port forwarding
location /webapi {
proxy_pass http://127.0.0.1:8180;
proxy_redirect 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;
proxy_set_header Authorization "Basic ZnJlZXN3aXRjaDp3b3Jrcw==";
}
#for lunahoge port forwarding
location /mediafiles {
proxy_pass http://127.0.0.1:9090/;
proxy_redirect 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;
}
server localhost:3000;
server localhost:3001;
}
server {
listen 80;
server_name localhost;
root /www/luna-server/public;
# individual nginx logs for this lunas-erver vhost
access_log /var/lib/luna/log/luna-server_access.log;
error_log /var/lib/luna/log/luna-server_error.log;
location / {
try_files $uri @luna-server;
}
location @luna-server {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
client_max_body_size 360M;
client_body_buffer_size 5256K;
proxy_pass http://lunaserver;
}
#for monitorix
location /monitorix {
index index.html;
}
location ~ \.pl|cgi$ {
# try_files $uri =404;
gzip off;
fastcgi_pass 127.0.0.1:8999;
fastcgi_index index.pl;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Originating-IP $remote_addr;
proxy_set_header HTTP_REMOTE_ADDR $remote_addr;
proxy_set_header REMOTE_ADDR $remote_addr;
}
#for freeswtich port forwarding
location /webapi {
proxy_pass http://127.0.0.1:8180;
proxy_redirect 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;
proxy_set_header Authorization "Basic ZnJlZXN3aXRjaDp3b3Jrcw==";
}
#for lunahoge port forwarding
location /mediafiles {
proxy_pass http://127.0.0.1:9090/;
proxy_redirect 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;
}
}
静态文件:
通过正则表达式,我们可让 nginx 识别出各种静态文件,例如 images 路径下的所有请求可以写为:
location ~ ^/assets/ {
expires 1y;
add_header Cache-Control public;
add_header ETag "";
break;
}
location ~ ^/uploads/ {
expires 1y;
add_header Cache-Control public;
add_header ETag "";
break;
}
对于例如图片、静态 HTML 文件、js 脚本文件和 css 样式文件等,我们希望 Nginx 直接处理并返回给浏览器,这样可以大大的加快网页浏览时的速度。因此对于这类文件我们需要通过 root 指令来指定文件的存放路径,同时因为这类文件并不常修改,通过 expires
指令来控制其在浏览器的缓存,以减少不必要的请求。 expires
指令可以控制 HTTP 应答中的“ Expires ”和“ Cache-Control ”的头标(起到控制页面缓存的作用)。您可以使用例如以下的格式来书写 Expires:
- nginx config example
- An ant config example.
- iptable config example
- varnish config example
- nginx-config
- ubuntu server partation config example
- Nginx Openresty example
- kohana nginx config
- nginx forward proxy config
- Nginx 配置文件config
- Nginx Basic Config
- Nginx Load Balancer Config
- Nginx config hight throughput
- nginx config.conf配置
- Nginx虚拟主机配置实例(Nginx VirtualHost Example)
- Nginx服务器配置HTTPS nginx.config 配置文件
- server config(nginx apache varnish)
- TypeSafe config & HOCON + Read properties in java (with example)
- window XP上配置Eclipse+CDT+MinGW
- 多个Icon的APk——实现多程序入口总结
- SpringSecurity入门
- 一分钟学会 log4net(c#) 配置及使用
- android 环境搭建
- nginx config example
- C#发送Email邮件的方法解析
- 3.10.5 指针的 “near” 和 “far” 指定
- WCF处理异常
- CentOS 6 最小化安装VNC Server
- 教你如何在wordpress添加统计代码
- JSP过滤器的应用 编码过滤器
- ubuntu12.04更新源(http://blog.chinaunix.net/uid-26404477-id-3382633.html)
- Android中singleTask模式没起作用!!