search
HomeOperation and MaintenanceNginxHow to install and deploy Nginx in Centos 6.5 64-bit

1. Introduction to nginx

nginx is a web server that can also be used for load balancing and reverse proxy. The most commonly used one at present is load balancing. I will not give a detailed introduction. There are many introductions to Baidu. Let’s go directly to the installation steps

2. nginx installation

1. Download nginx and related components

Linux system is centos 6.5 64-bit, I switched directly to the root user to install

Centos 6.5 64位中Nginx安装部署的方法

Enter the user directory to download the program

Centos 6.5 64位中Nginx安装部署的方法

Download related Component

[root@localhost src]# wget http://nginx.org/download/nginx-1.10.2.tar.gz
省略安装内容...
[root@localhost src]# wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
省略安装内容...
[root@localhost src]# wget http://zlib.net/zlib-1.2.11.tar.gz
省略安装内容...
[root@localhost src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
省略安装内容...

Install c compilation environment, if it is already installed, you can skip

[root@localhost src]# yum install gcc-c++
省略安装内容...
期间会有确认提示输入y回车
is this ok [y/n]:y
省略安装内容...

2. Install nginx and related components

openssl installation

[root@localhost src]# tar zxvf openssl-fips-2.0.10.tar.gz
省略安装内容...
[root@localhost src]# cd openssl-fips-2.0.10
[root@localhost openssl-fips-2.0.10]# ./config && make && make install
省略安装内容...

pcre installation

[root@localhost src]# tar zxvf pcre-8.40.tar.gz
省略安装内容...
[root@localhost src]# cd pcre-8.40
[root@localhost pcre-8.40]# ./configure && make && make install
省略安装内容...

zlib installation

[root@localhost src]# tar zxvf zlib-1.2.11.tar.gz
省略安装内容...
[root@localhost src]# cd zlib-1.2.11
[root@localhost zlib-1.2.11]# ./configure && make && make install
省略安装内容...

nginx installation

[root@localhost src]# tar zxvf nginx-1.10.2.tar.gz
省略安装内容...
[root@localhost src]# cd nginx-1.10.2
[root@localhost nginx-1.10.2]# ./configure && make && make install
省略安装内容...

3. Start nginx

First find out where nginx is installed.

Centos 6.5 64位中Nginx安装部署的方法

Enter the nginx directory and start

Centos 6.5 64位中Nginx安装部署的方法

An error was reported, error while loading shared libraries: libpcre.so.1 : cannot open shared object file: no such file or directory, solve the problem as follows

1.用whereis libpcre.so.1命令找到libpcre.so.1在哪里
2.用ln -s /usr/local/lib/libpcre.so.1 /lib64命令做个软连接就可以了
3.用sbin/nginx启动nginx
4.用ps -aux | grep nginx查看状态

[root@localhost nginx]# whereis libpcre.so.1
[root@localhost nginx]# ln -s /usr/local/lib/libpcre.so.1 /lib64
[root@localhost nginx]# sbin/nginx
[root@localhost nginx]# ps -aux | grep nginx

Centos 6.5 64位中Nginx安装部署的方法

Enter the graphical interface of the Linux system, open the browser and enter localhost and you will see the following picture , indicating that nginx started successfully

Centos 6.5 64位中Nginx安装部署的方法

Basic operations of nginx

启动
[root@localhost ~]# /usr/local/nginx/sbin/nginx
停止/重启
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop(quit、reload)
命令帮助
[root@localhost ~]# /usr/local/nginx/sbin/nginx -h
验证配置文件
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

4. Simple configuration of nginx

Open nginx The configuration file is located in the conf folder in the nginx directory.

Centos 6.5 64位中Nginx安装部署的方法

Let’s briefly introduce the syntax of vim.

By default, vim cannot be entered after it is opened. You need to press a key to do so. The operations are as follows: Start editing: Press the "i" or "insert" key to exit editing: "esc" key to exit vim: ":q" save vim: ":w" save and exit vim: ":wq" exit vim without saving : ":q!"

"#" represents comments. The most important thing is that the server{} block represents each web site. For detailed configuration introduction, you can check out my other configuration article, here Let’s temporarily set up three sites

Centos 6.5 64位中Nginx安装部署的方法

Use different ports 80, 81, and 82 respectively. Save and exit and restart nginx

Centos 6.5 64位中Nginx安装部署的方法

5. Enable external network access

In the Linux system, by default there are all ports of the firewall iptables manager. Only the default remote connection port 22 is enabled and the others are closed. The 80 we set above etc. are also closed, so we need to open the application port first

Method 1Close the firewall directly, which has better performance but poorer security. If there is a front-end firewall, you can Take this approach

关闭防火墙
[root@localhost ~]# service iptables stop
关闭开机自启动防火墙
[root@localhost ~]# chkconfig iptables off
[root@localhost ~]# chkconfig --list|grep ipt

Centos 6.5 64位中Nginx安装部署的方法

Method 2Add the opened port to the firewall whitelist. This method is safer but the performance is relatively poor

编辑防火墙白名单
[root@localhost ~]# vim /etc/sysconfig/iptables
增加下面一行代码
-a input -p tcp -m state -- state new -m tcp --dport 80 -j accept
保存退出,重启防火墙
[root@localhost ~]# service iptables restart

Centos 6.5 64位中Nginx安装部署的方法

Linux configuration is complete. Use another computer instead of the computer where nginx is installed. I am using the windows system. Configure the host in "c:\windows\system32 Configure domain name redirection in hosts under \drivers\etc"

10.11.13.22 nginx.test.com nginx.test1.com nginx.test2.com

Then cmd and ping this again Is the domain name correctly pointed to this IP

Centos 6.5 64位中Nginx安装部署的方法

After pointing it correctly, telnet to port 80 to see if it can communicate with the port (if telnet prompts that there is no such command, the client is not installed) , just install it after enabling or disabling the windows function)

Centos 6.5 64位中Nginx安装部署的方法

Get the following interface and it means successful communication

Centos 6.5 64位中Nginx安装部署的方法

打开这台windows系统内的浏览器,输入nginx.test.com会得到以下结果,就说明外网访问成功

Centos 6.5 64位中Nginx安装部署的方法

如果防火墙你依然启用,只是设置了启用端口,那我们访问81那个端口会发现无法访问,因为我并没有加入白名单

Centos 6.5 64位中Nginx安装部署的方法

到此nginx服务器雏形部署完成。

6、nginx负载均衡配置

 nginx集反向代理和负载均衡于一身,在配置文件中修改配就可以实现

首先我们打开配置文件

[root@localhost nginx]# vim conf/nginx.conf

 每一个server就是一个虚拟主机,我们有一个当作web服务器来使用

listen 80;代表监听80端口
server_name xxx.com;代表外网访问的域名
location / {};代表一个过滤器,/匹配所有请求,我们还可以根据自己的情况定义不同的过滤,比如对静态文件js、css、image制定专属过滤
root html;代表站点根目录
index index.html;代表默认主页

 Centos 6.5 64位中Nginx安装部署的方法

这样配置完毕我们输入域名就可以访问到该站点了。

负载均衡功能往往在接收到某个请求后分配到后端的多台服务器上,那我们就需要upstream{}块来配合使用

upstream xxx{};upstream模块是命名一个后端服务器组,组名必须为后端服务器站点域名,内部可以写多台服务器ip和port,还可以设置跳转规则及权重等等
ip_hash;代表使用ip地址方式分配跳转后端服务器,同一ip请求每次都会访问同一台后端服务器
server;代表后端服务器地址

server{};server模块依然是接收外部请求的部分
server_name;代表外网访问域名
location / {};同样代表过滤器,用于制定不同请求的不同操作
proxy_pass;代表后端服务器组名,此组名必须为后端服务器站点域名

server_name和upstream{}的组名可以不一致,server_name是外网访问接收请求的域名,upstream{}的组名是跳转后端服务器时站点访问的域名

 Centos 6.5 64位中Nginx安装部署的方法

配置一下windows的host将我们要访问的域名aaa.test.com指向linux

Centos 6.5 64位中Nginx安装部署的方法

因为硬件有限,我是将windows中的iis作为nginx的后端服务器,所以配置一下iis的站点域名

Centos 6.5 64位中Nginx安装部署的方法

打开cmd再ping一下aaa.test.com确实指向linux系统了,再打开浏览器输入aaa.test.com会显示bbb这个站点就代表负载成功了。

Centos 6.5 64位中Nginx安装部署的方法

The above is the detailed content of How to install and deploy Nginx in Centos 6.5 64-bit. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
NGINX Unit: Key Features and CapabilitiesNGINX Unit: Key Features and CapabilitiesApr 25, 2025 am 12:17 AM

NGINXUnit is an open source application server that supports multiple programming languages ​​and provides functions such as dynamic configuration, zero downtime updates and built-in load balancing. 1. Dynamic configuration: You can modify the configuration without restarting. 2. Multilingual support: compatible with Python, Go, Java, PHP, etc. 3. Zero downtime update: Supports application updates that do not interrupt services. 4. Built-in load balancing: Requests can be distributed to multiple application instances.

NGINX Unit vs. Other Application ServersNGINX Unit vs. Other Application ServersApr 24, 2025 am 12:14 AM

NGINXUnit is better than ApacheTomcat, Gunicorn and Node.js built-in HTTP servers, suitable for multilingual projects and dynamic configuration requirements. 1) Supports multiple programming languages, 2) Provides dynamic configuration reloading, 3) Built-in load balancing function, suitable for projects that require high scalability and reliability.

NGINX Unit: The Architecture and How It WorksNGINX Unit: The Architecture and How It WorksApr 23, 2025 am 12:18 AM

NGINXUnit improves application performance and manageability with its modular architecture and dynamic reconfiguration capabilities. 1) Modular design includes master processes, routers and application processes, supporting efficient management and expansion. 2) Dynamic reconfiguration allows seamless update of configuration at runtime, suitable for CI/CD environments. 3) Multilingual support is implemented through dynamic loading of language runtime, improving development flexibility. 4) High performance is achieved through event-driven models and asynchronous I/O, and remains efficient even under high concurrency. 5) Security is improved by isolating application processes and reducing the mutual influence between applications.

Using NGINX Unit: Deploying and Managing ApplicationsUsing NGINX Unit: Deploying and Managing ApplicationsApr 22, 2025 am 12:06 AM

NGINXUnit can be used to deploy and manage applications in multiple languages. 1) Install NGINXUnit. 2) Configure it to run different types of applications such as Python and PHP. 3) Use its dynamic configuration function for application management. Through these steps, you can efficiently deploy and manage applications and improve project efficiency.

NGINX vs. Apache: A Comparative Analysis of Web ServersNGINX vs. Apache: A Comparative Analysis of Web ServersApr 21, 2025 am 12:08 AM

NGINX is more suitable for handling high concurrent connections, while Apache is more suitable for scenarios where complex configurations and module extensions are required. 1.NGINX is known for its high performance and low resource consumption, and is suitable for high concurrency. 2.Apache is known for its stability and rich module extensions, which are suitable for complex configuration needs.

NGINX Unit's Advantages: Flexibility and PerformanceNGINX Unit's Advantages: Flexibility and PerformanceApr 20, 2025 am 12:07 AM

NGINXUnit improves application flexibility and performance with its dynamic configuration and high-performance architecture. 1. Dynamic configuration allows the application configuration to be adjusted without restarting the server. 2. High performance is reflected in event-driven and non-blocking architectures and multi-process models, and can efficiently handle concurrent connections and utilize multi-core CPUs.

NGINX vs. Apache: Performance, Scalability, and EfficiencyNGINX vs. Apache: Performance, Scalability, and EfficiencyApr 19, 2025 am 12:05 AM

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

The Ultimate Showdown: NGINX vs. ApacheThe Ultimate Showdown: NGINX vs. ApacheApr 18, 2025 am 12:02 AM

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)