Summary of Nginx502 error causes and solutions
1. Troubleshooting NGINX 502 errors NGINX 502 Bad Gateway error is a problem with FastCGI, causing NGINX 502 errors are more likely. Combine some found online and 502 Bad List the problems and troubleshooting methods related to Gateway errors, starting with the FastCGI configuration: 1. Whether the FastCGI process has started 2. Whether the number of FastCGI worker processes is not enough Run netstat -anpo | grep “php-cgi” | wc -l Judging whether it is close to the FastCGI process, close to the value set in the configuration file, indicating that the number of worker processes is too small 3. The execution time of FastCGI is too long Increase the following parameter values according to the actual situation fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; 4. FastCGI Buffer is not enough nginx is the same as apache, it has front-end buffer limit, you can adjust the buffer parameters fastcgi_buffer_size 32k; fastcgi_buffers 8 32k; 5. Proxy Buffer is not enough If you use Proxying, adjust proxy_buffer_size 16k; proxy_buffers 4 16k; See: http://www.server110.com 6. https forwarding configuration error The correct configuration method server_name www.mydomain.com; location /myproj/repos { set $fixed_destination $http_destination; if ( $http_destination ~* ^https(.*)$ ) { set $fixed_destination http$1; } proxy_set_header Host…
Store Nginx cache content in memory
Method 1: 1. Modify /etc/fstab to mount the memory file system, and specify the selinux context tmpfs /var/tmp/nginx/proxy_cache tmpfs defaults,size=100m,cOntext=system_u:object_r:httpd_cache_t:s0 tmpfs /var/tmp/nginx/proxy_temp tmpfs defaults, size=100m, cOntext=system_u:object_r:httpd_cache_t:s0 Then mkdir -p /var/tmp/nginx/proxy_cache mount -t ramfs none /var/tmp/nginx/proxy_cache mkdir -p /var/tmp/nginx/proxy_temp mount -t ramfs none /var/tmp/nginx/proxy_temp 2. Specify the proxy_temp_path of nginx in http proxy_temp_path /var/tmp/nginx/proxy_temp ; proxy_cache_path /var/tmp/nginx/proxy_cache levels=1:2 keys_zOne=cache_one:64m inactive=1d max_size=128m; add_header X-Cache HIT-LT; The above method is suitable for xen linux VPS and dedicated hosting Method 2: New cache storage address mkdir /dev/shm/proxy_cache chmod 1777 /dev/shm/proxy_cache mkdir -p /var/tmp/nginx/proxy_cache mount –bind /dev/shm/proxy_cache /var/tmp/nginx/proxy_cache mkdir /dev/shm/proxy_temp chmod 1777 /dev/shm/proxy_temp mkdir -p /var/tmp/nginx/proxy_temp mount –bind /dev/shm/proxy_temp /var/tmp/nginx/proxy_temp Add the following statement to the nginx main configuration file proxy_temp_path /var/tmp/nginx/proxy_temp ; proxy_cache_path /var/tmp/nginx/proxy_cache levels=1:2 keys_zOne=cache_one:64m inactive=1d max_size=128m; add_header X-Cache HIT-LT; Method 2 is suitable for openvz linux VPS and should be under /proc/user_beancounters according to openvz VPS The barrier value of the next shmpages line determines the max_size value of proxy_cache_path, Remarks: The nginx cache requires a version higher than 0.7.48 to support it.
Nginx server setup static content cache
Use the reverse proxy module of nginx, which has a proxy_store switch, indicating whether to save the content obtained by reverse proxy locally. I did an experiment with my own BLOG. For the visit request, if it is an ASP file request, it will be directly proxied to the backend (dynamic content and may have COOKIE judgment), and other content, some in the local directory, will be sent directly to the client IE. If not locally, then proxy to the backend server. Since ZBLOG generates static HTML for each log, the pressure on the back-end server is only the call of the ASP file, and the static content is only read from the back-end for the first time, and then all requests are made locally from the front-end. The specific configuration is as follows: “ “ location ~* \.asp { root /web/htdocs1; 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; 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 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; proxy_max_temp_file_size 128m; proxy_store off; proxy_pass http://test; } location / { root /web/htdocs1; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header…
How to configure Nginx reverse proxy on LinuxVPS server
Nginx is a high-performance HTTP and reverse proxy server. The HTTP application of Nginx has been introduced many times before, such as. The next thing to say is. What is a reverse proxy? A reverse proxy refers to a proxy server that accepts a connection request on the Internet, then forwards the request to a server on an internal (or other) network, and returns the result obtained from the server to the client requesting a connection on the Internet. How to do it: For example, I want to build a domain name of www.server110.com on the VPS to use reverse proxy to access twitter. First, add an A record for the domain name www.server110.com to the IP of the VPS in the domain name management of the domain name registrar. Modify the Nginx configuration file on the VPS and add the following: server { listen 80; Server_name www.server110.com; Location / { http://twitter.com/; Proxy_redirect off; $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } After adding, execute: /usr/local/nginx/sbin/nginx -t to check whether the configuration is normal, if it shows: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok????? configuration file /usr/local/nginx/conf/nginx.conf test is If it is successful, it is normal; otherwise, modify the configuration according to…
Nginx server setting identity password authentication
1. Nginx ID card password verification #cd /usr/local/nginx/conf #mkdir htpasswd /usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/htpasswd/home lenfeng #Add user named lenfeng New password: (enter your password here) Re-type new password: (enter your password again) Adding password for user #cd /usr/local/nginx/conf #mkdir htpasswd /usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/htpasswd/home lenfeng #Add user named lenfeng New password: (enter your password here) Re-type new password: (re-enter your password) Adding password for user http://it.yooxue.com/home/data/index.html (the directory exists in the /www/wwwroot/home/data/ directory) Put the following configuration into the virtual host directory, and when you visit http://it.yooxue.com/home/, you will be prompted for password verification: location ~ ^/(home)/ { root /www/wwwroot/count; auth_basic “LT-COUNT-Home”; auth_basic_user_file /usr/local/nginx/conf/htpasswd/home; } location ~ ^/(home)/ { root /www/wwwroot/count; auth_basic “LT-COUNT-Home”; auth_basic_user_file /usr/local/nginx/conf/htpasswd/home; } 2. Prohibit Nginx from accessing certain types of files For example, to prohibit access to *.txt files under Nginx, the configuration method is as follows: location ~* \.(txt|doc)$ { if (-f $request_filename) { root /data/www/wwwroot/lenfeng/test; #rewrite …..can redirect to a URL break; } } location ~* \.(txt|doc)$ { if (-f $request_filename) { root /data/www/wwwroot/lenfeng/test; #rewrite ….. can redirect to a certain URL break; } } The second method: location ~* \.(txt|doc)${ root /data/www/wwwroot/lenfeng/test; deny all; } location ~* \.(txt|doc)${ root /data/www/wwwroot/lenfeng/test; deny all; } The third…
Solve Nginx’s 502badgateway error instance
Phenomenon: The web site is configured with load balancing, using nginx, some pages are OK, but after logging in, 502 bad gateway is reported Reason: After logging in, there will be an operation to write COOKIE to the client, causing the header to be larger than normal access (according to the upstream sent too big header in the nginx error log /usr/local/nginx/logs while reading response header from upstream determined) solution: This is caused by a bug in the nginx buffer. The page consumption of our website may occupy too much buffer. We are nginx reverse proxy Proxy is used by nginx when forwarding as a client. If the header is too large and exceeds the default 1k, the above upstream will be triggered sent too big header (to put it bluntly, nginx sends external requests to the backend apache , the header returned by apache is too large for nginx to handle. server { listen 80; server_name www.server110.com ; large_client_header_buffers 4 16k; #charset koi8-r; # access_log off; location /{ #Add these 3 lines, proxy_buffer_size 64k; proxy_buffers 32 32k; proxy_busy_buffers_size 128k; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; set $baiduspider”; if ( $http_user_agent ~ Baiduspider) {…
Nginx reverse proxy Apache server
When installing Nginx there are tips and tricks needed. After mastering these, you can better use the relevant Nginx server. Let’s take a look at the introduction of related issues about installing Nginx. Because the server apache can’t resist the current concurrency. After adding the front-end squid configuration. The problem is still unsolvable. Most of the page programs are dynamic. Fastcgi cannot be used to handle them. Therefore, I want to use Nginx as reverse proxyapache. The whole configuration and installation process is very simple. Considering high concurrency Next, some optimizations were done before installation. The current configuration can withstand more than 3000 concurrency. It doesn’t seem to be particularly large? Oh~~ But enough~~ There are only a few 499 problems.. I look forward to someone discussing with me to solve them The process of installing Nginx 1 Create users and groups /usr/sbin/groupadd www /usr/sbin/useradd -g www www 2 Install pcre to install Nginx to support rewrite, which is convenient for future needs wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.8.tar.gz the tar zxvf pcre-7.8.tar.gz cd pcre-7.8/ ./configure make && make install 3 Install Nginx 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…
How to configure Nginx front-end Apache back-end server server environment
I used to be confused about the host2ez host, which uses nginx, but it is perfectly compatible with apache. After some tossing, I realized that as long as Nginx is used as the front-end server to process static files, Apache is used as the back-end server. But, the price is poor memory and less… 1. Basic knowledge 1.1, reverse proxy process The process of Nginx front-end and Apache back-end is actually very simple. First, the user accesses nginx on port 80, then nginx keeps the static content for itself, and forwards the rest to non-port 80 apache, and then sends it back to nginx after apache finishes processing. 1.2. Nginx location basics For details, see “Nginx Location Command Basics”, add reverse proxy at different Locations, Nginx The front end plays a completely different role. 2. Edit the Nginx configuration file vim /usr/local/nginx/conf/nginx.conf 2.1. Add “proxy_set_header” command Edit the Nginx configuration file, add the corresponding code in the “http” field, and send the real IP to the backend. vim /usr/local/nginx/conf/nginx.conf # Add the specified header information when making a request to the backend server proxy_set_header Host $host; # Send the real IP to the backend server proxy_set_header X-Real-IP $remote_addr; #Let the…
Nginx+jdk+tomcat environment installation configuration
in CentOS It is very easy to install Nginx+jdk+mysql+tomca in 5.5. You only need to install environment package and nginx with yum, unzip and install jdk and tomcat, configure profile, server.xml and nginx.conf files. Specific steps are as follows: 1. Install the environment package First use the yum command to install and upgrade the required libraries. yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-server krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers 2. Install nginx How to install Nginx: http://blog.163.com/leijie131421@126/blog/static/424111452011112102447696/ three. install jdk 1. Install jdk. wget http://cds-esd.sun.com/ESD6/JSCDL/jdk/6u24-b07/jdk-6u24-linux-i586.bin?AuthParam=1301239661_e064c3c5e58eb26bc89c2d3e83aaff41&TicketId=B%2Fw2nByASltMSBdFOVN fkgPr&GroupName=CDS&FilePath=/ESD6/JSCDL/jdk/6u24 -b07/jdk-6u24-linux-i586.bin&File=jdk-6u24-linux-i586.bin If you cannot download due to permission issues, please download it on the windows side and upload it to the centos server. After downloading, modify the file attribute of jdk-6u23-linux-i586.bin to be executable, and then execute the program to install #chmod +x jdk-6u23-linux-i586.bin #cd ./jdk-6u23-linux-i586.bin #mv jdk1.6.0_23 /usr/local/jdk 2. Edit the profile file, set the startup file java startup execution environment file #vi /etc/profile Add the following at the end of the file JAVA_HOME=”/usr/local/jdk” CLASS_PATH=”$JAVA_HOME/lib:$JAVA_HOME/jre/lib” PATH=”.:$PATH:%JAVA_HOME/bin” CATALINA_HOME=”/usr/local/tomcat” export JAVA_HOME CATALINA_HOME Save and exit vi, execute the following command to…
Use Nginx+gridfs to realize distributed storage of pictures
1. Preparation sudo yum -y install pcre-devel openssl-devel GeoIP-devel zlib-devel 2. Download nginx-gridfs source code, and add mongodb-mongo-c-driver source code to nginx-gridfs/mongo- c-driver # The download address will not be available due to the change of the code version number, bloggers, search it yourself. . wget https://download.github.com/mdirolf-nginx-gridfs-v0.8-0-gb5f8113.tar.gz tar ?zxvf mdirolf-nginx-gridfs-v0.8-0-gb5f8113.tar.gz mv mdirolf-nginx-gridfs-v0.8-0-gb5f8113 mdirolf-nginx-gridfs-v0.8 wget https://download.github.com/mongodb-mongo-c-driver-v0.3-0-g74cc0b8.tar.gz tar ?zxvf mongodb-mongo-c-driver-v0.3-0-g74cc0b8.tar.gz mv mongodb-mongo-c-driver-v0.3-0-g74cc0b8/* mdirolf-nginx-gridfs-v0.8/mongo-c-driver rm ?rf mongodb-mongo-c-driver-v0.3-0-g74cc0b8 3. Install nginx, specify the nginx-gridfs directory and jointly compile with nginx wget http://nginx.org/download/nginx-1.0.1.tar.gz tar ?zxvf nginx-1.0.1.tar.gz cd nginx-1.0.1 ./configure –prefix=/usr/local/nginx –with-openssl=/usr/include/openssl –with-http_stub_status_module –add-module=/home/cdh/Downloads/mdirolf-nginx-gridfs make ?j8 sudo make install ?j8 4. Install mongodb and start wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.8.1.tgz tar ?xvf mongodb-linux-i686-1.8.1.tgz sudo mv mongodb-linux-i686-1.8.1 /usr/local/mongodb sudo mkdir ?p /tmp/mongodb/data /usr/local/mongodb/bin/mongod –dbpath /tmp/mongodb/data –logpath /tmp/mongodb/data/log.log?fork 5. Configure nginx-gridfs sudo vim /usr/local/nginx/conf/nginx.conf location /pics/ { gridfs pics field=filename type=string; mongo 127.0.0.1:27017; } gridfs: keyword for nginx to identify plugins pics: db name [root_collection]: select collection, such as root_collection=blog, mongod will look for blog.files and blog.chunks two blocks, the default is fs [field]: query field, make sure there is this field name in mongdb, support _id, filename, can be omitted, the default is _id [type]: Explain the data type of the field, support objectid, int, string, can be omitted, the…