Nginx Reverse proxy has a lot of problems that we need to solve, many of them are based on the installation of the problem, after the installation of the relevant debugging also let a lot of people headaches unceasingly. Here is a brief introduction to the installation and commissioning.
Because the server Apache cannot withstand the current concurrency. Plus the front-end squid configuration, The problem still cannot be solved. And the page program is mostly dynamic. You cannot use fastcgi to handle it. Therefore, you want to use the Nginx reverse proxy Apache. The entire configuration installation process is simple. When considering high concurrency, Some optimizations have been made before installation. The current configuration can withstand more than 3000 concurrent. It's not that big, huh? But it's just a few 499 questions. I expect someone to discuss the solution with me.
Part 1th: Installation
1 Set up users and groups
/usr/sbin/groupadd www
/usr/sbin/useradd-g www www
2 installation Pcre Let Nginx reverse proxy support rewrite convenient after the need
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz
tar zxvf pcre-7.8.tar.gz
CD pcre-7.8/
./configure make
&& make install
3 Installation Nginx Reverse proxy
wget http://sysoev.ru/nginx/nginx-0.7.58.tar.gz
tar zxvf nginx-0.7.58.tar.gz
cd nginx-0.7.58/
./ Configure--user=www--group=www--prefix=/usr/
local/webserver/nginx--with-http_stub_status_module
-- With-http_ssl_module--with-cc-opt= '-o2 '--with-cpu-opt
=opteron make
&& make install
Note that the--with-cc-opt= '-o2 '--with-cpu-opt=opteron above are compiler optimizations, and the most commonly used now is-02 instead of 3. The model of the corresponding CPU.
Part 2nd: Configuring and Optimizing Configuration Files
1 nginx.conf configuration file:
User www www.
Worker_processes 4;
# [Debug | info | notice | warn | error | crit] Error_log/usr/local/webserver/nginx/logs/nginx_error.log crit;
Pid/usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors the can is opened by this process.
Worker_rlimit_nofile 51200;
events {use Epoll;
Worker_connections 51200;
} http {include mime.types;
Default_type Application/octet-stream;
Source_charset GB2312;
Server_names_hash_bucket_size 256;
Client_header_buffer_size 256k;
Large_client_header_buffers 4 256k;
#size limits client_max_body_size 50m;
Client_body_buffer_size 256k;
Client_header_timeout 3m;
Client_body_timeout 3m;
Send_timeout 3m;
#参数都有所调整. The purpose is to resolve some 502 499 error sendfile on the agent process;
Tcp_nopush on; Keepalive_timeout 120;
#参数加大 to solve the 502 error tcp_nodelay on when acting as an agent;
Include vhosts/upstream.conf;
Include vhosts/bbs.linuxtone.conf;
}
2 upstream.conf configuration file (This is also the way to do the load configuration
upstream.conf
upstream bbs.linuxtone.com {
server 192.168.1.4:8099;
}
3 Site configuration file
bbs.linuxtone.conf server {Listen 80;
server_name bbs.linuxtone.conf;
CharSet GB2312;
Index index.html index.htm;
root/date/wwwroot/linuxtone/;
Location ~ ^/nginxstatus/{stub_status on;
Access_log off;
} location/{root/date/wwwroot/linuxtone/;
Proxy_redirect off;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header remote-host $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Client_max_body_size 50m;
Client_body_buffer_size 256k;
Proxy_connect_timeout 30;
Proxy_send_timeout 30;
Proxy_read_timeout 60;
Proxy_buffer_size 256k;
Proxy_buffers 4 256k;
Proxy_busy_buffers_size 256k;
Proxy_temp_file_write_size 256k;
Proxy_next_upstream Error timeout Invalid_header http_500 http_503 http_404;
Proxy_max_temp_file_size 128m;
Proxy_pass http://bbs.linuxtone.com; }
The parameters are adjusted. To resolve some 502 499 errors that occur during the agent process
#Add Expires header for static content
location ~* \. ( jpg|jpeg|gif|png|swf) $ {
if (f $request _filename) {
root/date/wwwroot/linuxtone/;
Expires 1d;
break;
}
}
Log_format access ' $remote _addr-$remote _user [$time _local] ' $request '
$status $body _bytes_sent ' $http _referer ' "
$http _user_agent" $http _x_forwarded_for ";
Access_log/exp/nginxlogs/bbs.linuxtone_access.log access;
}
Common instructions
Here's a look at some of the Nginx reverse proxy common directives
Proxy_pass directives
Grammar
Proxy_pass [url | upstream]
Role
This directive is used to set the proxy server port or socket, and the URL
Proxy_redirect directives
Grammar
Proxy_redirect [off | default | REDIRECT Replacement]
Role
This directive is used to change the "location" and "refresh" in the reply header header of the proxy server
Add:
This command function I have not mastered, the actual settings are off, if you have any understanding, welcome blog under the message guide me
Proxy_next_upstream directives
Grammar
Copy Code code as follows:
Proxy_next_upstream [Error|timeout|invalid_header|http_500|http_502|http_503|http_504|http_404|off]
Role
This directive is used to set when in which case the request is forwarded to the next server. In a upstream load balancing proxy pool, you can use this directive to forward requests to the next server in the pool, assuming that one server in the backend cannot access or return a specified error response code.
Parameter description
Error: Errors when connecting to a server, sending a request, reading an answer message
Timeout: timeout when connecting to a server, when delivering requests, and when reading back-end server reply messages
Invalid_header: Back-end server returns an empty or wrong answer
HTTP_[500|502|503|504|404]: Back-end server returns the specified response status code
OFF: Disallow forwarding of requests to the next back-end server
Proxy_set_header directives
Grammar
Proxy_set_header Header Value
Role
This directive allows the redefinition or addition of header lines to the request information forwarded to the proxy server, which can be text, can be a variable, can be a combination of text and variables