"Go" Linux Service Deployment--java (iii) Nginx

Source: Internet
Author: User
Tags nginx server nginx load balancing

Original address: Nginx Linux detailed installation Deployment tutorial

First, Nginx Introduction

Nginx is a Web server can also be used to do load balancing and reverse proxy use, the current use of the most is load balancing, specific introduction I do not introduce Baidu a lot, the following directly into the installation steps

Second, Nginx installation

1. Download Nginx and related components

Download related components

[[email protected] src]# wget http://nginx.org/download/nginx-1.10.2.tar.gz omit installation content ... [Email protected] src]# wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz  Omit installation content ... [[email protected] src]# wget http://zlib.net/zlib-1.2.11.tar.gz omit installation content ... [[email protected] src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ pcre-8.40.tar.gz omitting installation content ...

Install a C + + compilation environment, as installed to skip

[[email protected] src]# Yum install gcc-c++ This ok [y/n]:y omit installation content ...

2. Installation of Nginx and related components * *

OpenSSL installation

[[Email protected] src]# tar zxvf openssl-fips-2.0.10. tar.gz Omit Installation content ... [Email protected] src]# CD OpenSSL-fips-2.0.10[[email protected] OpenSSL-fips-2.0.10]#./config & & Make && make install omit installation content ...

Pcre Installation

[[Email protected] src]# tar zxvf pcre-8.40. tar.gz Omit Installation content ... [Email protected] src]# CD pcre-8.40[[email protected] pcre-8.40]#./configure && Make && Make install omit installation content ...

Zlib installation

[[Email protected] src]# tar zxvf zlib-1.2.11. tar.gz Omit Installation content ... [Email protected] src]# CD zlib-1.2.11[[email protected] zlib-1.2.11]#./configure && Make && Amp Make install omit installation content ...

Nginx Installation

[[Email protected] src]# tar zxvf nginx-1.10.2. tar.gz Omit Installation content ... [[Email protected] src]# CD nginx-1.10.2[[email protected] nginx-1.10.2]#./configure && Make && make install omit installation content ...

3. Start nginx**

Let's find out where the Nginx is installed.

/usr/local/nginx

Enter Nginx directory and start

[[email protected] src] #cd/usr/local//sbin/nginx

Could be an error.

 while loading shared libraries:libpcre.so.1:cannot open Shared object file:no such file or directory

Fix it in the following way

1. Use the Whereis libpcre.so.1 command to find out where the libpcre.so.1 is . 2. Use the Ln-s/usr/local/lib/libpcre.so.1/lib64 command to make a soft connection . 3. Use sbin/nginx to start Nginx4. With Ps-aux | grep nginx View status [[email protected] nginx]# Whereis libpcre.so. 1-s/usr/local/lib/libpcre.so.1/lib64[[email protected] nginx]# sbin/-aux | grep nginx into the Linux system graphical interface, open browser input localhost will see, indicating that Nginx started successfully

  Basic operation of Nginx

~]#/usr/local/nginx/sbin/nginx stop /~]#/usr/local/nginx/sbin/nginx-~]#/usr/local/nginx /sbin/nginx-~]#/usr/local/nginx/sbin/nginx-~]# vim/usr/local/nginx/conf/nginx.conf

4, simple configuration Nginx

Open nginx Config file under the Conf folder in the Nginx directory

[Email protected] nginx]# vim conf/nginx.conf

Save exit and restart Nginx

[Email protected] nginx]# Sbin/nginx-s Reload

5. Open Internet access

In the Linux system, the default firewall Iptables manager all the ports, only enable the default remote connection 22 port others are closed, we set the above 80 and so on is also closed, so we need to first open the application port

Method One: Close the firewall directly, so that the performance is good, but the security is poor, if there is a front firewall can take this way

~~~]# chkconfig--list|grep IPT

Method Two adds the open port to the firewall whitelist, which is safer but less performance

~]# vim/etc/sysconfig/iptables Add the following line of code -A input-p tcp-m State-the state new-m TCP--dport-~]# Service Iptables Restart
Linux configuration is complete, using another computer instead of installing Nginx computer, I am using the Windows system, configure the host in the "C:\Windows\System32\drivers\etc" under the hosts in the configuration of domain redirection 10.11.13.22 nginx.test.com nginx.test1.com Nginx.test2.com then cmd and then ping the domain correctly pointing to this IP on the correct point after the Telnet 80 port to see if you can communicate with the port (if Telnet prompts that no this command is not installed by the client, after you enable or disable the installation of Windows features, then Available)

Get the following interface and communicate success on behalf of

Open the browser in this Windows system, enter nginx.test.com will get the following results, indicating that the external network access to success

    

To this Nginx server prototype deployment completed.

6, Nginx Load Balancing configuration

Nginx set reverse proxy and load balancing in a, modify the configuration file can be implemented

First we open the configuration file

[[email protected] nginx]# vim conf//{}; Represents a filter,/ matches all requests, we can also define different filters according to our own situation, such as the static file JS, CSS, Image to create the exclusive filter root HTML; Represents the site root index index.html; represents the default home page

This completes the configuration, we can enter the domain name to access the site.

Load balancing is often allocated to multiple servers on the backend after receiving a request, so we need upstream{} blocks to work with

/ {}; also represents a filter for different operation Proxy_pass for different requests; The group name for the back-end server group name, which must be a back-end server site domain name server_name and upstream{}, can be inconsistent, Server_ Name is the domain name that the extranet accesses to receive the request, the group name of upstream{} is the domain name that the site accesses when jumping back-end server

Configure Windows host to point to the domain name aaa.test.com we want to access to Linux

Nginx load function is configured to complete.

"Go" Linux Service Deployment--java (iii) Nginx

Related Article

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.