NGINX reverse proxy server configuration

Source: Internet
Author: User
Tags nginx reverse proxy

NGINX reverse proxy server configuration

The system is CENTOS5.9.

Http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm wget-c

Rpm-ivh nginx-release-centos-5-0.el5.ngx.noarch.rpm

Ulimit-HSn 65536

Yum-y install nginx

Cd/home # enter the Directory

Mkdir-p/home/proxy_temp_dir # proxy_temp_dir and proxy_cache_dir must be in the same partition.

Mkdir-p/home/proxy_cache_dir # The two folders proxy_cache_dir and proxy_temp_dir must be in the same partition.

Chown nginx. nginx-R proxy_cache_dir proxy_temp_dir # Set the directory owner

Chmod-R 777 proxy_cache_dir proxy_temp_dir # Set Directory Permissions

Back up the original configuration file

Cd/etc/nginx

Mv nginx. conf nginx. conf. bak

Mv conf. d/default. confconf. d/default. conf. bak

The following is the configuration file nginx. conf that I configured.

User nginx;
Worker_processes 2;
Error_log/var/log/nginx/error. log warn;
Pid/var/run/nginx. pid;
Worker_rlimit_nofile 65535;
Events {
Use epoll;
Worker_connections 65535;
}

Http {
Include/etc/nginx/mime. types;
Default_type application/octet-stream;
Charset UTF-8;
Server_names_hash_bucket_size 128;
Client_header_buffer_size 32 k;
Large_client_header_buffers 4 32 k;
Client_max_body_size 300 m;

Sendfile on;
Tcp_nopush on;
Server_tokens off;
Keepalive_timeout 60;
Tcp_nodelay on;
Client_body_buffer_size 512 k;
Proxy_connect_timeout 5;
Proxy_read_timeout 60;
Proxy_send_timeout 5;
Proxy_buffer_size 16 k;
Proxy_buffers 4 64 k;
Proxy_busy_buffers_size 128 k;
Proxy_temp_file_write_size 128 k;

Gzip on;
Gzip_min_length 1 k;
Gzip_buffers 4 16 k;
Gzip_http_version 1.1;
Gzip_comp_level 2;
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;

# Note: The paths specified by proxy_temp_path and proxy_cache_path must be in the same partition.
Proxy_temp_path/home/proxy_temp_dir;
# Set the name of the Web cache area to cache_one. The size of the memory cache space is 200 MB. cache is cleared once a day, and the size of the hard disk cache space is 10 GB.
Proxy_cache_path/home/proxy_cache_dir levels = keys_zone = NAME: 64 m inactive = 1d max_size = 10g;
Include/etc/nginx/conf. d/*. conf;
}

Default Configuration File conf. d/default. conf

This file prohibits access by Unbound Domain names or IP addresses.

Server {
Listen 80 default;
Server_name _;
Return 500;
Access_log off;
}

The following is the configuration file conf. d/blog. conf of the reverse proxy of the website.

Server {
Listen 80;
Server_name blog.com; # website Domain Name
Location /{
Proxy_pass http://www.google.com;
Proxy_redirect off;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
Proxy_cache NAME; # use the NAME keys_zone
Proxy_cache_valid 200 302 1 h; # status codes 200 and 302 are saved for 1 hour
Proxy_cache_valid 301 1d; # Save the status code for one day
Proxy_cache_valid any 1 m; # Save the remaining one minute
}
}

You can copy multiple conf. d/blog. conf files from multiple websites to modify the corresponding website. Then you can complete the configuration and restart NGINX.

Server nginx restart

Then observe the cache directory

Tree/home/proxy_cache_dir

If a file is generated, the reverse proxy server is successfully cached !!

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.