Configuration of Nginx Reverse proxy

Source: Internet
Author: User
Tags nginx reverse proxy

    • Chapter:nginx Basic Operation Explanation
    1. 1. nginx Port Modification Problem
    2. 2. Nginx 301 Redirection Configuration
    3. 3. Configure the Nginx to support PHP under Windows
    4. 4. Configure the Nginx to support PHP under Linux
    5. 5. install PHP and php-fpm in the form of source code compilation
    6. 6. One practice of Nginx Multi-site configuration
    7. 7. configuration of Nginx reverse proxy

Nginx as a Web server an important function is the reverse proxy. In fact, we in the previous article "Nginx Multi-site configuration of a practice" in the use of Nginx reverse proxy, here simply to mention.

Here are the settings for configuring Nginx as a reverse proxy for tornado:

View Source print?
01 upstream tornado {
02     server 127.0.0.1:8888;
03 }
04  
05 server {
06     listen   80;
07     root /root/nmapp2_venv;
08     index index.py index.html;
09  
10     server_name server;
11  
12     location / {
13         #if (!-e $request_filename) {
14         #    rewrite ^/(.*)$ /index.py/$1 last;
15         #}
16     }
17  
18     location ~ /index\.py {
19         proxy_pass_header Server;
20         proxy_set_header Host $http_host;
21         proxy_set_header X-Real-IP $remote_addr;
22         proxy_set_header X-Scheme $scheme;
23         proxy_pass http://tornado;
24     }
25 }

Nginx Reverse proxy instructions do not need to add additional modules, the default comes with proxy_pass instructions, only need to modify the configuration file can be implemented reverse proxy.

Let me give you one more example. For example, to configure the backend to run the Apache service IP and port, that is, our goal is to achieve through Http://ip:port can access to your website.

Just create a new vhost.conf and add the following (remember to modify the IP and domain name for your IP and domain name). Modify the nginx.conf, add include quancha.conf to http{} segment, Reload Nginx is available.

Nginx Reverse Proxy Template:

View Source print?
01 ## Basic reverse proxy server ##
02 upstream apachephp  {
03     server ip:8080; #Apache
04 }
05  
06 ## Start www.nowamagic.net ##
07 server {
08     listen 80;
09     server_name  www.nowamagic.net;
10  
11     access_log  logs/quancha.access.logmain;
12     error_log  logs/quancha.error.log;
13     root   html;
14     index  index.html index.htm index.php;
15  
16     ## send request back to apache ##
17     location / {
18         proxy_pass  http://apachephp;
19  
20         #Proxy Settings
21         proxy_redirect     off;
22         proxy_set_header   Host             $host;
23         proxy_set_header   X-Real-IP        $remote_addr;
24         proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
25         proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
26         proxy_max_temp_file_size 0;
27         proxy_connect_timeout      90;
28         proxy_send_timeout         90;
29         proxy_read_timeout         90;
30         proxy_buffer_size          4k;
31         proxy_buffers              4 32k;
32         proxy_busy_buffers_size    64k;
33         proxy_temp_file_write_size 64k;
34    }
35 }

This completes the Nginx reverse proxy configuration.

Configuration of Nginx Reverse proxy

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.