Tips on return configuration of Nginx

Tips on return configuration of Nginx

The return keyword of Nginx belongs to the HttpRewriteModule module: Syntax: return http status code Default: None Context: server, location, if This command will end the execution and directly return the http status code to the client. Supported http status codes: 200, 204, 400, 402-406, 408, 410, 411, 413, 416, 500-504, and non-standard 444 status codes. How to use: #Return 403 Access Forbidden that does not meet the rules location /download/ { rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break; return 403; } Tips These tips are not introduced in the wiki, but the system supports them. The configuration file is as follows: server { server_name test.liguangming.com; listen 80; location / { Add_header Content-Type “text/plain;charset=utf-8”; return 200 “Your IP Address:$remote_addr”; } } Executing the request: curl -i http://test.liguangming.com The returned content is as follows: HTTP/1.1 200 OK Server: nginx/1.0.13 Date: Thu, 10 May 2012 10:01:15 GMT Content-Type: application/octet-stream Content-Length: 30 Connection: keep-alive Content-Type: text/plain;charset=utf-8 Your IP Address: 123.128.217.19 It’s fun, and what else, such as the following configuration file: server { server_name test.liguangming.com; listen 80; location / { Return http://liguangming.com/; } } Executing the request: curl -i http://test.liguangming.com The returned content is as follows: HTTP/1.1 302 Moved Temporarily Server: nginx/1.0.13 Date: Thu, 10 May…

The method of obtaining the real IP of visitors in the LNAMP (Apache+nginx) environment

nginx forwards to the back-end apache, the default IP address is 127.0.0.1, if you want to get the real IP address, you can use the following two methods: 1. Add the following content to http in the nginx.conf configuration file: proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 2. Download apache’s third-party module mod_rpaf (1) Download: wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz (2) Install mod_rpaf tar zxf mod_rpaf-0.6.tar.gz cd mod_rpaf-0.6 /usr/local/webserver/apache/bin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c (3) Configure the http.conf configuration file of apache and save it, add the following content: LoadModule rpaf_module modules/mod_rpaf-2.0.so RPAF Enable On RPAF set hostname On RPAFproxy_ips 192.168.1.100 127.0.0.1 #Fill in nginx web forwarded ip address RPAF header X-Forwarded-For (4) Finally, restart nginx and apache to check whether the log is normal.

Convert a Java program to run as a Windows service

1. First, please download the latest version of Java Service Wrapper, click me to download. 2. Prepare the following files and copy them to the test directory. These files can be found in the download package: wrapper.dll wrapper.exe wrapper.jar3, write wrapper.conf, also put it under the same level directory, the content is as follows# Java Application full path wrapper.java.command=java wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp #Define the classpath where the program runs wrapper.java.classpath.1=wrapper.jar wrapper.java.classpath.2=[jar file/path] # Java Library Path (location of Wrapper.DLL or libwrapper.so) wrapper.java.library.path.1=. # Java Additional Parameters #wrapper.java.additional.1= # Initial Java Heap Size (in MB) #wrapper.java.initmemory=3 # Maximum Java Heap Size (in MB) #wrapper.java.maxmemory=64 # Running Main Class wrapper.app.parameter.1= wrapper.console.format=PM wrapper.console.loglevel=INFO wrapper.logfile=Beanskt.log wrapper.logfile.format=LPTM wrapper.logfile.loglevel=INFO wrapper.logfile.maxsize=0 wrapper.logfile.maxfiles=0 wrapper.syslog.loglevel=NONE #window service configuration wrapper.console.title=samplesvr #service name wrapper.ntservice.name=samplesvr # display name wrapper.ntservice.displayname= sample Service # description wrapper.ntservice.description=sample Service # Dependencies wrapper.ntservice.dependency.1= # Start mode: AUTO_START or DEMAND_START wrapper.ntservice.starttype=AUTO_START # Whether to interact. wrapper.ntservice.interactive=false 4. Run the test and install the service 》Test running is normal wrapper.exe -c wrapper.conf 》Installation Service wrapper.exe -i wrapper.conf 》Uninstall service wrapper.exe -r wrapper.conf 》Start wrapper.exe -t wrapper.conf “Stop wrapper.exe -p wrapper.conf

Pseudo-static rule conversion method between .htAccess and httpd.ini and Nginx

Servers are often changed, so these rules also need to be converted. I have made a lot of inquiries, and there are a lot of Baidu and Google, but there is no document explaining it, so I write down the results of my research just while the iron is hot. Have prepared for future inquiries! An example of httpd.ini ————————————————– ————————————————– ——- [ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32 # Protect httpd.ini and httpd.parse.errors files # from accessing through HTTP # duoduo Rewrite rules RewriteRule ^/index\.html$ /index\.php RewriteRule ^/sitemap\.html$ /sitemap\.php RewriteRule ^/malllist\.html$ /malllist\.php ————————————————– ————————————————– ——- Convert to .htaccess Pay attention to the difference and convert it like this next time. ————————————————– ————————————————– ——- RewriteEngine On RewriteBase / # duoduo Rewrite rules RewriteRule index\.html$ /index\.php RewriteRule sitemap\.html$ /sitemap\.php RewriteRule malllist\.html$ /malllist\.php ————————————————– ————————————————– ——- httpd.ini conversion .htaccess General rule description: 1. [ISAPI_Rewrite] # 3600 = 1 hour CacheClockRate 3600 RepeatLimit 32 # Protect httpd.ini and httpd.parse.errors files # from accessing through HTTP Replaced with: RewriteEngine On RewriteBase / 2. RewriteRule ^/index\.html$ /index\.php Remove ^/ RewriteRule index\.html$ /index\.php ————————————————– ————————————————– ——- Convert .htaccess to nginx Pay attention to the difference and convert it like this next time. ———————————–.htaccess————-…

Detailed explanation of lnamp (Nginx+Apache+MySQL+PHP) configuration process

After getting the VPS of DS, I decided to try the LNAMP framework to configure the server. The full text uses the aptitude installation and manual configuration of the Debian system. This is a small note. If you don’t like to spend time on yourself, you can consider 31sky’s LNAMP one-key package, which is suitable for CentOS, Debian and Ubuntu, installation is very convenient. If you like to configure yourself, you can learn from here. 1. About LNAMP The LNAMP architecture uses Nginx as the front end of the server, and Apache as the back end to process dynamic pages. Since Nginx handles static content better and Apache handles dynamic pages more stably, this architecture gives full play to the advantages of both. Of course, there are also shortcomings. When the website is set to be pseudo-static, how to let the server automatically choose fast resolution and give full play to the strengths of the two servers is worth studying. The installation and configuration of LNAMP is not difficult, but how to optimize the running memory on a VPS with small memory also poses many challenges. Regarding LNAMP, I saw a post called Mapn on hostloc. From the description on…

Nginx server configuration details

Nginx is a high-performance HTTP and reverse proxy server developed by Russian software engineer Igor Sysoev, with IMAP/POP3 and SMTP server functions. The biggest feature of Nginx is its support for high concurrency and efficient load balancing. It is a good substitute for Apache server in scenarios with high concurrency requirements. At present, well-known websites including Sina and Tencent have begun to use Nginx as a web application server. Nginx configures a magical web server. There are many things we need to pay attention to when using it. Next, let’s see how to configure the Nginx server simply and clearly. #running user user nobody nobody; #Start the process, adjust according to the hardware, greater than or equal to the number of cpu cores worker_processes 2; #Specify the maximum descriptor that the process can open worker_rlimit_nofile 204800; This instruction refers to the maximum number of file descriptors opened by a nginx process, and the theoretical value should be the maximum number of open files (ulimit -n) is divided by the number of nginx processes, but nginx allocation requests are not so uniform, so it is best to keep the same value as ulimit -n. now in linux The number of open…

Install Nginx server graphic tutorial under Linux

Install Nginx server graphic tutorial under Linux

What is Nginx? Nginx (“engine x”) is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server. Nginx is a good alternative to the Apache server in the case of high concurrent connections It is characterized by less memory and strong concurrency capability. In fact, the concurrency capability of nginx does perform better in the same type of web server. Currently, nginx is used in mainland China Website users include: Sina, Netease, Tencent, and the well-known micro-blog Plurk also uses nginx. Nginx as a load balancing server: Nginx can directly support Rails and PHP programs to serve externally internally, and can also support externally serving as an HTTP proxy server. Nginx is written in C, which is much better than Perlbal in terms of system resource overhead and CPU usage efficiency. As a mail proxy server: Nginx is also a very good mail proxy server (one of the original purposes of developing this product is also as a mail proxy server), Last.fm describes the successful and wonderful experience of using it. Nginx is a server with very simple installation, very concise configuration files (it can also support perl syntax), and very few bugs: Nginx is very…

Linux system and Nginx server environment remove index.PHP in codeigniter

There is an extra index.php in the original system url, which makes me uncomfortable. The static and elegant url is good-looking. Although it is fake, in fact, you only need to add the following configuration in nginx.conf: server { listen 80; server_name yourservername; location / { root /your/root/path/; index index.php index.html index.htm; if (-f $request_filename) { expires max; break; } #if (!-e $request_filename) { # rewrite ^/(.*)$ /index.php/$1 last; #} If ($request_filename !~ (js|css|images|robots/.txt|index/.php.*) ) {   rewrite ^/(.*)$ /index.php/$1 last; break; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php($|/) { root /your/root/path; fastcgi_pass 127.0.0.1:9000;   fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;   fastcgi_param PATH_INFO $fastcgi_path_info; Fastcgi_split_path_info ^(.+\.php)(.*)$; include fastcgi_params; } } Then $config[‘index_page’] in application/config/config.php of the codeigniter project = ”; That’s it. Then just refresh the page.

Linux system Nginx compilation and installation tutorial

1. Download nginx1.2.4 #Note: Download address: http://nginx.org/download/nginx-1.2.4.tar.gz wget -c http://nginx.org/download/nginx-1.2.4.tar.gz 2. Installation #Note: Installed to /usr/local/nginx by default tar -zxvf nginx-1.2.4.tar.gz cd nginx-1.2.4 ./configure If appears ./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using –without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library Statically from the source with nginx by using –with-pcre= option. #Note: install pcre-devel to solve the problem yum -y install pcre-devel # ./configure make #Note: A bunch of things will come out make install 3. Run /usr/local/nginx/sbin/nginx #Note: nginx uses port 80 by default. If port 80 is occupied, modify /usr/local/nginx/conf/nginx.conf server { listen 80; #My side is changed to 8081 #Check if nginx is normal [root@aaa nginx-1.2.4]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful 4. Test echo “test123” > /usr/local/nginx/html/index.html Then enter ip:8081 in the browser to see the content test123

Use OpenRestyngx_lua to prevent cc attacks

Use OpenRestyngx_lua to prevent cc attacks

This article introduces the use of openresty to implement the function of preventing cc attacks. Openresty official website http://openresty.org/cn/index.html. The following is the flow chart of anti-CC attack. According to the flow chart, we know that anti-CC attacks mainly include two parts, one is to limit the request speed, and the other is to send js jump code to the user to verify whether the request is legal. 1. Installation dependencies centos: yum install readline-devel pcre-devel openssl-devel ubuntu: apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl Second, luajit installation cd /tmp/ git clone http://luajit.org/git/luajit-2.0.git cd luajit-2.0/ make && make install ln -sf luajit-2.0.0-beta10 /usr/local/bin/luajit ln -sf /usr/local/lib/libluajit-5.1.so.2 /usr/lib/ Three, openresty installation cd /tmp wget http://agentzh.org/misc/nginx/ngx_openresty-1.2.4.13.tar.gz tar xzf ngx_openresty-1.2.4.13.tar.gz cd ngx_openresty-1.2.4.13/ ./configure –prefix=/usr/local/openresty –with-luajit make && make install Four, nginx configuration nginx.conf: http{ […] lua_shared_dict limit 10m; lua_shared_dict jsjump 10m; server { #lua_code_cache off; listen 80; server_name www.centos.bz; location / { default_type text/html; content_by_lua_file “/usr/local/openresty/nginx/conf/lua”; } location @cc { internal; root html; index index.html index.htm; } } } /usr/local/openresty/nginx/conf/lua file: local ip = ngx.var.binary_remote_addr local limit = ngx.shared.limit local req,_=limit:get(ip) if req then if req > 20 then ngx. exit(503) else limit:incr(ip,1) end else limit:set(ip,1,10) end local jsjump = ngx.shared.jsjump local uri…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索