当前位置: 操作系统/服务器>linux
本页文章导读:
▪Nginx动态文件与静态文件分离的方法 本节内容:
nginx中配置动静分离
首先,安装nginx:
代码示例:
[root@ /]# rpm -ivh /nginx-0.6.36-1.el5.i386.rpm
主配置文件nginx.conf
代码示例:
[root@ /]# cd /etc/nginx/
[root@ nginx]# ls nginx.conf
nginx.conf.........
▪nginx配置nagios之nginx.conf 本节内容:
nginx.conf
nginx.conf配置内容:
代码示例:
user nagios nagios;
worker_processes 4;
worker_cpu_affinity 00000001 00000010 00000100 00001000;
error_log /export/servers/nginx/logs.........
▪nginx反向代理中node节点获取真实IP的方法 本节内容:
在nginx的反向代理中node节点获取真实IP
前端为一个nginx 反向代理,结果:req.ip
始终取到nginx的IP。
为了取得客户端真实IP,需要做2个步骤,如下:
1,设置nginx转发时加上http hea.........
[1]Nginx动态文件与静态文件分离的方法
来源: 互联网 发布时间: 2013-12-24
本节内容:
nginx中配置动静分离
首先,安装nginx:
代码示例:
[root@ /]# rpm -ivh /nginx-0.6.36-1.el5.i386.rpm
主配置文件nginx.conf
代码示例:
[root@ /]# cd /etc/nginx/
[root@ nginx]# ls nginx.conf
nginx.conf
[root@ nginx]# vim /etc/nginx/nginx.conf
location / {
81 root /usr/share/nginx/html;
82 index index.html index.htm;
83 }
[root@ nginx]# ls nginx.conf
nginx.conf
[root@ nginx]# vim /etc/nginx/nginx.conf
location / {
81 root /usr/share/nginx/html;
82 index index.html index.htm;
83 }
nginx的主目录/usr/share/nginx/html
默认主页index.html index.htm;
在logformat下面添加:
代码示例:
upstream nginx{
server 192.168.1.27:80;
}
upstream tomcat{
server 192.168.1.25:8080;
}
location / {
if( $request_uri ~* ".*\.html$"){
proxy_pass http://nginx;
}
proxy_pass http://tomcat;
}
注意:
与ldirector整合时,验证的网页也要写一个。
[2]nginx配置nagios之nginx.conf
来源: 互联网 发布时间: 2013-12-24
本节内容:
nginx.conf
nginx.conf配置内容:
代码示例:
user nagios nagios;
worker_processes 4;
worker_cpu_affinity 00000001 00000010 00000100 00001000;
error_log /export/servers/nginx/logs/nginx_error.log notice;
pid /export/servers/nginx/logs/nginx.pid;
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
server_tokens off;
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 500m;
sendfile on;
tcp_nopush on;
keepalive_timeout 0;
tcp_nodelay on;
client_body_buffer_size 1024k;
fastcgi_intercept_errors on;
proxy_connect_timeout 90;
proxy_read_timeout 180;
proxy_send_timeout 180;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
server_name_in_redirect off;
proxy_hide_header X-Powered-By;
fastcgi_connect_timeout 320m;
fastcgi_send_timeout 320m;
fastcgi_read_timeout 320m;
gzip on;
gzip_min_length 100;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 9;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
error_page 400 401 402 403 404 = /40x.html;
# error_page 500 501 502 503 504 = /50x.html;
log_format nagios_logs '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /export/servers/nginx/logs/access_nagios.log nagios_logs;
fastcgi_buffer_size 512k;
fastcgi_buffers 24 512k;
fastcgi_busy_buffers_size 640k;
fastcgi_temp_file_write_size 640k;
include domains/*;
###########status#########
server
{
listen 80;
server_name status.nginx.com;
location / {
stub_status on;
access_log off;
}
}
}
worker_processes 4;
worker_cpu_affinity 00000001 00000010 00000100 00001000;
error_log /export/servers/nginx/logs/nginx_error.log notice;
pid /export/servers/nginx/logs/nginx.pid;
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
server_tokens off;
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 500m;
sendfile on;
tcp_nopush on;
keepalive_timeout 0;
tcp_nodelay on;
client_body_buffer_size 1024k;
fastcgi_intercept_errors on;
proxy_connect_timeout 90;
proxy_read_timeout 180;
proxy_send_timeout 180;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
server_name_in_redirect off;
proxy_hide_header X-Powered-By;
fastcgi_connect_timeout 320m;
fastcgi_send_timeout 320m;
fastcgi_read_timeout 320m;
gzip on;
gzip_min_length 100;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 9;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
error_page 400 401 402 403 404 = /40x.html;
# error_page 500 501 502 503 504 = /50x.html;
log_format nagios_logs '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /export/servers/nginx/logs/access_nagios.log nagios_logs;
fastcgi_buffer_size 512k;
fastcgi_buffers 24 512k;
fastcgi_busy_buffers_size 640k;
fastcgi_temp_file_write_size 640k;
include domains/*;
###########status#########
server
{
listen 80;
server_name status.nginx.com;
location / {
stub_status on;
access_log off;
}
}
}
[root@ conf]# q
-bash: q: command not found
[root@ conf]# vi nginx.conf
代码示例:
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 500m;
sendfile on;
tcp_nopush on;
keepalive_timeout 0;
tcp_nodelay on;
client_body_buffer_size 1024k;
fastcgi_intercept_errors on;
proxy_connect_timeout 90;
proxy_read_timeout 180;
proxy_send_timeout 180;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
server_name_in_redirect off;
proxy_hide_header X-Powered-By;
fastcgi_connect_timeout 320m;
fastcgi_send_timeout 320m;
fastcgi_read_timeout 320m;
gzip on;
gzip_min_length 100;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 9;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
error_page 400 401 402 403 404 = /40x.html;
# error_page 500 501 502 503 504 = /50x.html;
log_format nagios_logs '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /export/servers/nginx/logs/access_nagios.log nagios_logs;
fastcgi_buffer_size 512k;
fastcgi_buffers 24 512k;
fastcgi_busy_buffers_size 640k;
fastcgi_temp_file_write_size 640k;
include domains/*;
###########status#########
server
{
listen 80;
server_name status.nginx.com;
location / {
stub_status on;
access_log off;
}
}
}
'"$gzip_ratio"';
charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 500m;
sendfile on;
tcp_nopush on;
keepalive_timeout 0;
tcp_nodelay on;
client_body_buffer_size 1024k;
fastcgi_intercept_errors on;
proxy_connect_timeout 90;
proxy_read_timeout 180;
proxy_send_timeout 180;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
server_name_in_redirect off;
proxy_hide_header X-Powered-By;
fastcgi_connect_timeout 320m;
fastcgi_send_timeout 320m;
fastcgi_read_timeout 320m;
gzip on;
gzip_min_length 100;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 9;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
error_page 400 401 402 403 404 = /40x.html;
# error_page 500 501 502 503 504 = /50x.html;
log_format nagios_logs '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /export/servers/nginx/logs/access_nagios.log nagios_logs;
fastcgi_buffer_size 512k;
fastcgi_buffers 24 512k;
fastcgi_busy_buffers_size 640k;
fastcgi_temp_file_write_size 640k;
include domains/*;
###########status#########
server
{
listen 80;
server_name status.nginx.com;
location / {
stub_status on;
access_log off;
}
}
}
[3]nginx反向代理中node节点获取真实IP的方法
来源: 互联网 发布时间: 2013-12-24
本节内容:
在nginx的反向代理中node节点获取真实IP
前端为一个nginx 反向代理,结果:req.ip
始终取到nginx的IP。
为了取得客户端真实IP,需要做2个步骤,如下:
1,设置nginx转发时加上http header
2,在node中取出新加的header
nginx配置
代码示例:
location /svc/ {
proxy_pass http://192.168.1.111:8080;
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_pass http://192.168.1.111:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
以上增加了3个http header,其中X-Real-IP代表真实IP。
node节点的代码:
代码示例:
var real_ip = req.get("X-Real-IP") || req.get("X-Forwarded-For") || req.ip;
最新技术文章: