- Chapter:nginx Basic Operation Explanation
- 1. nginx Port Modification Problem
- 2. Nginx 301 Redirection Configuration
- 3. Configure the Nginx to support PHP under Windows
- 4. Configure the Nginx to support PHP under Linux
- 5. install PHP and php-fpm in the form of source code compilation
- 6. One practice of Nginx Multi-site configuration
- 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?
02 |
server 127.0.0.1:8888; |
07 |
root /root/nmapp2_venv; |
08 |
index index.py index.html; |
13 |
#if (!-e $request_filename) { |
14 |
# rewrite ^/(.*)$ /index.py/$1 last; |
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; |
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 ## |
03 |
server ip:8080; #Apache |
06 |
## Start www.nowamagic.net ## |
09 |
server_name www.nowamagic.net; |
11 |
access_log logs/quancha.access. log main; |
12 |
error_log logs/quancha.error. log ; |
14 |
index index.html index.htm index.php; |
16 |
## send request back to apache ## |
18 |
proxy_pass http: //apachephp; |
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; |
32 |
proxy_busy_buffers_size 64k; |
33 |
proxy_temp_file_write_size 64k; |
This completes the Nginx reverse proxy configuration.
Configuration of Nginx Reverse proxy