Configure nginx reverse proxy in CentOS

Source: Internet
Author: User

Configure nginx reverse proxy in CentOS

System centos6.2

Install contos first, which is omitted here.

1. Install gcc

Yum install gcc-c ++

Ii. Install the required dependent Libraries

Yum-y install zlib-devel openssl -- devel pcre-devel

3. Uninstall the old version.

View: find-name nginx

Uninstall: yum remove nginx


4. Download The nginx source code and decompress it. (download the source code from the official website. The following is an official link)

Wget-chttp: // nginx.org/download/nginx-1.6.2.tar.gz

Tar-zxvf nginx-1.6.2.tar.gz

Music nginx-1.6.2 nginx

Cd nginx

./Configure -- user = nginx -- group = nginx -- prefix =/usr/local/nginx

With-http_addition_module

-- With-http_flv_module -- with-http_gzip_static_module

-- With-http_realip_module -- with-http_ssl_module

-- With-http_stub_status_module -- with-http_sub_module

With-http_dav_module

Make

Make install


5. Create nginx users and user groups

Groupadd-r nginx useradd-s/sbin/nologin-g nginx-r nginxcd to the nginx directory to see if sbin/nginx can be started # If no error is reported, it means OK 6. Configure nginx, edit the configuration file nginx. conf

Vim/usr/local/nginx/conf/nginx. conf

Remove the # before the first user and change it:

User nginx;

Set the worker sub-process of the nginx service, for example, to 2:

Worker_processes 2;

Remove the # Before the following two rows:

Error_log logs/error. log

Pid logs/nginx. pid

Remove the following #, which is the log Configuration:

Log_formatmain '$ remote_addr-$ remote_user [$ time_local] "$ request "'

'$ Status $ body_bytes_sent "$ http_referer "'

'"$ Http_user_agent" "$ http_x_forwarded_for "';

Access_log logs/access. log main;

Upstream proxy_test {

Server 192.168.4.69: 80; # If you want to test it, replace it with the ip address of the proxy backend.

Server 192.168.4.68: 80;

}

This is the server Segment configuration

Server {

Listen 80;

Server_namewww.test.com; # The domain name to be accessed. The test domain name I use here

Charset utf8;

Location /{

Proxy_pass http: // proxy_test;

Proxy_set_header Host $ host;

Proxy_set_header X-Real-IP $ remote_addr;

Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;

}

}


Save and exit!

Nginx smooth restart: nginx-s reload # load the configuration just added.

VII. test:

Start the server on the backend and set the test file test.html on the page files 192.168.4.69and 68. the content is this is test 69, this is test 68, which makes it easy to see which server is accessed.

Configure the host locally and use www.test.com to access the files on the backend server,

For example, www.test.com/test.html,

This is displayed in the browser, indicating that the configuration is OK.

If you have any questions, add our Technical Group (284215611)

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.