Nginx Series Tutorials: FAQ collation

Source: Internet
Author: User
Keywords Nginx faq Series Tutorials
Tags .url address address bar browser configure domain domain name error

Most of the questions in the FAQ come from http://www.stackoverflow.com and http://www.serverfault.com, some of which may not have been verified by me.

Nginx How to replace errors

Q: Can I return with a 503 error (overloaded or temporarily unavailable) instead of 502 as an answer?
A: Configure the fastcgi_intercept_errors directive and set it to on, and then use the error_page directive:

Location/{Fastcgi_pass 127.0.0.1:9001; fastcgi_intercept_errors on; Error_page 502 =503/error_page.html;

Nginx how to rewrite 404 to other pages

Q: Can I rewrite the requested nonexistent file to index.php?
A: Use the try_files directive:

Try_files $uri $uri//index.php

$uri and $uri/will determine whether the requested URI is an existing file or directory, and if not, it will be rewritten to the last argument, index.php

Nginx How to save the requested host header for the agent's request

Q: When using Nginx's Proxy_pass proxy for a backend server (application), if the back-end server has multiple virtual hosts, the proxy request does not produce the correct answer (no host request header in the Nginx-initiated request), how to solve the problem?
A: Set the host header using the Proxy_set_header directive:

Location/{proxy_pass http://my_app_upstream proxy_set_header Host $host;

How to configure the Nginx rewrite, will not cause the browser URL address redirection?

The P parameter in the Q:apache rewrite rule is represented as a force proxy, even if this parameter can be used to say one domain name rewrite to another domain name without causing the URL of the browser address bar to change, nginx how to achieve this function?
A: Use rewrite with Proxy_pass:

Location ~ ^/frompath/{rewrite ^/frompath/(. *) $/topath/$1 break; Proxy_pass http://www.domain.com;}

If the request is http://www.test.com/frompath/page.php, it will be rewritten to http://www.domain.com/topath/page.php without causing a change in the URL in the browser's address bar

How do I override a URI with a parameter?

Q: How to use Nginx to rewrite/test.php?id=1&action=delete to/action.php?id=1&action=delete
A: The parameter is saved in the variable $query_string, and the default parameter follows the overridden URL, which adds a question mark to the new rule:

Set $query $query _string;rewrite/test.php/action.php $query?

If you require that the overridden parameter be different from the parameter before the rewrite, you can make a regular match for the $query_string variable and set the variable with the set so that you can use them in the rewrite rule.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.