详细资料参考
反向代理
server
{
listen 80;
server_name localhost;
client_max_body_size 1024M;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host:$server_port;
}
}
负载均衡
upstream back {
server 192.168.1.1:8080;
server 192.168.1.2:8081;
}
server
{
listen 80;
server_name localhost;
client_max_body_size 1024M;
location / {
proxy_pass http://back;
proxy_set_header Host $host:$server_port;
}
}
- weight :权重,越大越优先。
- ip_hash:固定访问同意后端服务器,解决session问题。
- url_hash:按照url访问,需要安装模块。
- fair:按响应时间访问,时间短优先。需要安装模块。
web服务器
server
{
listen 80 ;
#listen [::]:80;
server_name ****;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/****;
#error_page 404 /404.html;
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
# error_log /dev/null;
# access_log off;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.^(well-known)
{
deny all;
}
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
}
access_log ****.com.$year-$month-$day.access.log;
}
正向代理服务器
resolver 114.114.114.114 8.8.8.8;
server {
resolver_timeout 5s;
listen 80;
location / {
proxy_pass http://$host$request_uri;
}
}
网友评论