Set Nginx custom 404 error page and return 404 status code
The initial configuration is as follows, and it turns out that the returned status code is 200, and the following configuration is wrong. http { …… fastcgi_intercept_errors on; …… } #—————————————- server{ #It’s just a jump error_page 404 = /404.html; } The correct setting method should be like this (remove the equal sign) http { ….. fastcgi_intercept_errors on; ….. } #—————————————- server{ error_page 404 /404.html; } Start Nginx smoothly to solve this problem /usr/local/nginx/sbin/nginx -s reload When accessing, a custom 404 page appears, and a 404 status code is returned
CentOS system sets Nginx service to start and run automatically
After completing the basic configuration of nginx, you can configure it as a service for easy management. At the same time, the service can be automatically started when the system starts. 1. First configure the service script and create the file /etc/rc.d/init.d/nginx2, the content of which is as follows: #!/bin/sh #chkconfig: 2345 10 90 #name: nginx #description: Nginx Service Script # case $1 in start) Echo “Starting Nginx…” /usr/local/nginx2/sbin/nginx -c /usr/local/nginx2/conf/nginx.conf ;; stop) echo “Stopping Nginx…” /usr/bin/killall -s QUIT nginx ;; restart) echo “Reloading Nginx…” $0 stop $0 start ;; *) Echo “Usage: $0 {start|stop|restart}” esac exit 0 2. Configure autostart chkconfig –add nginx2 //Add to self-starting service chkconfig –level 2345 nginx2 off //Adjust the start of different system levels chkconfig –level 2345 nginx2 on //Adjust the start of different system levels chkconfig | grep nginx2 //View status
Nginx-specific HTTP status code: 499
rfc2616 defines 400-417 error codes, and 418-499 is a custom category. So it can be judged that 499 is defined by nginx itself. When analyzing nginx logs, sometimes 499 errors are found, which do not exist in apache logs, so I feel very confused. View related documents Check the nginx source code and you will find the following explanation about the nginx code # vim src/http/ngx_http_special_response.c …………………………….. ngx_string(ngx_http_error_495_page), /* 495, https certificate error */ ngx_string(ngx_http_error_496_page), /* 496, https no certificate */ ngx_string(ngx_http_error_497_page), /* 497, http to https */ ngx_string(ngx_http_error_404_page), /* 498, canceled */ ngx_null_string, /* 499, client has closed connection */ …………………………………………… ………….. It can be seen from the above explanation that the 499 code is likely to be caused by the server processing the request for too long, and the client disconnected because it could not bear it.
CentOS system yum way to configure and install nginx server
1. Change the yum source to NetEase’s source to speed up vi /etc/yum.repos.d/CentOS-Base.repo The changes are as follows # CentOS-Base.repo # # This file uses a new mirrorlist system developed by Lance Davis for CentOS. # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-$releasever-Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 #released updates [updates] name=CentOS-$releasever-Updates #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 #packages used/produced in the build but not released [addons] name=CentOS-$releasever-Addons #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons #baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/ baseurl=http://mirrors.163.com/centos/$releasever/addons/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 #additional packages that may be useful [extras] name=CentOS-$releasever-Extras #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever-Plus #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/ baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 Two, update yum yum -y update 3. Use the yum command that comes with the CentOS Linux system to install and upgrade the required program library LANG=C yum -y install…
CentOS system installs Nginx+Uwsgi server environment
The most troublesome thing about using Python as a web application is to configure the server environment. It is not as easy as PHP to configure and then throw the .php file into the web directory. And the current configuration of python There are also many methods for the web environment, which is really frustrating for novices. Here is a record of the nginx+uwsgi environment I compiled and configured on CentOS. Get ready Update the system first, and install the compilation environment and so on. yum update yum install python python-devel libxml2 libxml2-devel python-setuptools zlib-devel wget openssl-devel pcre pcre-devel sudo gcc make autoconf automake Compile and install uwsgi The official website of uwsgi is http://projects.unbit.it/uwsgi/, here we download its current stable version. wget http://projects.unbit.it/downloads/uwsgi-1.0.4.tar.gz tar -zxvf uwsgi-1.0.4.tar.gz # decompress mv uwsgi-1.0.4 uwsgi # Renamed to uwsgi, just for convenience cd uwsgi # switch to uwsgi directory python setup.py build # compile and install make Next, move the compiled executable file to /usr/bin Compile and install nginx The official website of nginx is http://nginx.org, here we still download its stable version. cd ~ wget http://nginx.org/download/nginx-1.0.13.tar.gz tar -zxvf nginx.1.0.13.tar.gz mv nginx-1.0.13 nginx cd nginx ./configure –prefix=/usr/local/nginx # Compilation option configuration, simplified here…
Detailed process of CentOS compiling and installing Nginx
1. Preparations 1.1. Install OpenSSL (search by yourself) 1.2, prepare pcre The library pere is for nginx to support regular expressions. It is just prepared, not installed, to avoid errors in 64-bit systems. wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz tar -zxf pcre-8.30 wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz tar -zxf pcre-8.30 1.3. Prepare the zlib library It is also just preparation, not installation, in order to avoid errors in 64-bit systems. wget http://sourceforge.net/projects/libpng/files/zlib/1.2.6/zlib-1.2.6.tar.gz/download tar -zxf zlib-1.2.6.tar.gz wget http://sourceforge.net/projects/libpng/files/zlib/1.2.6/zlib-1.2.6.tar.gz/download tar -zxf zlib-1.2.6.tar.gz 2. Compile and install 2.1. Download and create a temporary directory wget http://nginx.org/download/nginx-1.1.9.tar.gz tar -zxf nginx-1.1.9.tar.gz cd nginx-1.1.9 mkdir -p /var/tmp/nginx wget http://nginx.org/download/nginx-1.1.9.tar.gz tar -zxf nginx-1.1.9.tar.gz cd nginx-1.1.9 mkdir -p /var/tmp/nginx 2.2, compilation and installation ./configure –prefix=/usr/local/nginx \ –pid-path=/var/run/nginx.pid \ –lock-path=/var/lock/nginx.lock \ –with-http_ssl_module \ –with-http_dav_module \ –with-http_flv_module \ –with-http_realip_module \ –with-http_gzip_static_module \ –with-http_stub_status_module \ –with-mail –with-mail_ssl_module \ –with-pcre=../pcre-8.30 \ –with-zlib=../zlib-1.2.6 \ –with-debug \ –http-client-body-temp-path=/var/tmp/nginx/client \ –http-proxy-temp-path=/var/tmp/nginx/proxy \ –http-fastcgi-temp-path=/var/tmp/nginx/fastcgi \ –http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ –http-scgi-temp-path=/var/tmp/nginx/scgi make && make install ln -s /usr/local/nginx/sbin/nginx /usr/sbin/ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ./configure –prefix=/usr/local/nginx \ –pid-path=/var/run/nginx.pid \ –lock-path=/var/lock/nginx.lock \ –with-http_ssl_module \ –with-http_dav_module \ –with-http_flv_module \ –with-http_realip_module \ –with-http_gzip_static_module \ –with-http_stub_status_module \ –with-mail –with-mail_ssl_module \ –with-pcre=../pcre-8.30 \ –with-zlib=../zlib-1.2.6 \ –with-debug…
Installation and configuration method of CentOS6.2 system fastdfs
Steps to install and configure FastDFS under centos6.2 system: 1: Install libevent (libevent-2.0.16-stable) ## Uninstall system comes with libevent rpm -qa | grep libevent rpm -e libevent* ## Install libevent for Trackerd and Storaged nodes cd /home/ylh wget https://github.com/downloads/libevent/libevent/libevent-2.0.16-stable.tar.gz tar -zxvf libevent-2.0.16-stable.tar.gz cd libevent-2.0.16-stable make clean ./configure make && make install ##Create a soft link for libevent to the /lib library, 64-bit system corresponds to /lib64 ln -s /usr/local/lib/libevent* /lib/ ln -s /usr/local/lib/libevent* /lib64/ 2: Install FastDFS for the Trackerd node, and modify the configuration file /etc/fdfs/tracker.conf( If Trackerd needs to use the built-in web server, you need to modify the make file, enable WITH_HTTPD=1 and then compile) cd /home/ylh wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gz tar -zxvf FastDFS_v3.06.tar.gz cd FastDFS_v3.06 ./make.sh ./make.sh install ##Create storage directory mkdir /home/ylh/fastdfs ##Modify the configuration file. vim /etc/fdfs/tracker.conf Save and exit after modification ## start trackerd /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf 3: Install FastDFS for the Storaged node, the Storaged node also needs libevent, see the first step for the installation steps cd /home/ylh wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gz tar -zxvf FastDFS_v3.06.tar.gz cd FastDFS_v3.06 ./make.sh ./make.sh install 4: Install a web server for the Storaged node. The Storaged node can use nginx or apache to provide http download service. Here we choose nginx.…
CentOS6.3 system installation and configuration Nginx
Installation Instructions System environment: CentOS-6.3 Software: nginx-1.2.6.tar.gz Installation method: source code compilation and installation Installation location: /usr/local/nginx Download address: http://nginx.org/en/download.html Prerequisites Before installing nginx, make sure that the system has installed g++, gcc, openssl-devel, pcre-devel, and zlib-devel software. Install necessary software: [root@admin /]#yum install gcc-c++ yum -y install zlib zlib-devel openssl openssl –devel pcre pcre-devel Check the system installed Nginx: [root@admin local]# find -name nginx ./nginx ./nginx/sbin/nginx ./nginx-1.2.6/objs/nginx Uninstall the original Nginx [root@admin /]# yum remove nginx Install Upload the installation package file to /usr/local and perform the following operations: [root@admin local]# cd /usr/local [root@admin local]# tar -zxv -f nginx-1.2.6.tar.gz [root@admin local]# rm -rf nginx-1.2.6.tar.gz [root@admin local]# mv nginx-1.2.6 nginx [root@admin local]# cd /usr/local/nginx [root@admin nginx]# ./configure –prefix=/usr/local/nginx [root@admin nginx]# make [root@admin nginx]# make install configuration #Modify firewall configuration: [root@admin nginx-1.2.6]# vi + /etc/sysconfig/iptables #Add configuration item -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT #restart firewall [root@admin nginx-1.2.6]# service iptables restart Start #Method 1 [root@admin nginx-1.2.6]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #Method 2 [root@admin nginx-1.2.6]# cd /usr/local/nginx/sbin [root@admin sbin]# ./nginx Stop #Query nginx main process number ps -ef | grep nginx #stop process kill -QUIT main process ID #quickstop kill -TERM main process number #…
CentOS6.2 system yum way to install and configure LNMP environment
1. Configure the firewall, open port 80 and port 3306 vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT (allow port 80 through the firewall) -A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT (allow port 3306 through the firewall) Special reminder: Many netizens add these two rules to the last line of the firewall configuration, causing the firewall to fail to start. The correct one should be added below the default port 22 rule After adding, the firewall rules are as follows: #################################################### ####### # Firewall configuration written by system-config-firewall # Manual customization of this file is not recommended. *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT -A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT -A INPUT -j REJECT –reject-with icmp-host-prohibited -A FORWARD -j REJECT –reject-with icmp-host-prohibited COMMIT #################################################### ####### /etc/init.d/iptables…
CentOS system LNMP production environment configuration process
CentOS minimal installation, and then create a new repo first # vi /etc/yum.repos.d/centos.21andy.com.repo Put the following content [21Andy.com] name=21Andy.com Packages for Enterprise Linux 5 – $basearch baseurl=http://www.21andy.com/centos/5/$basearch/ enabled=1 gpgcheck=0 protect=1 Enable EPEL repo CentOS i386 enter the following command rpm -ihv http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm CentOS x86_64 Enter the following command rpm -ihv http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm Then import key rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL OK, one-click installation yum -y install nginx mysql-server php-fpm php-cli php-pdo php-mysql php-mcrypt php-mbstring php-gd php-tidy php-xml php-xmlrpc php-pear php-pecl-memcache php-eaccelerator Finally, run yum -y update, all are the latest If you want to use the latest stable version of nginx 0.7.65, put yum -y install nginx Change to yum -y install nginx-stable That’s it After installing, you can already play like this service mysqld start service php-fpm start service nginx start Don’t forget to set it to start at boot chkconfig –level 345 mysqld on chkconfig –level 345 php-fpm on chkconfig –level 345 nginx on The configuration files are all found under /etc See how the installation is automatic Dependencies Resolved ==================================================== ======== Package Arch Version Repository Size ==================================================== ======== Installing: mysql x86_64 5.0.89-1.el5 21Andy.com 3.5 M mysql-server x86_64 5.0.89-1.el5 21Andy.com 10 M nginx x86_64 0.8.33-3.el5 21Andy.com 422 k php-cli x86_64 5.3.1-2.el5…