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.
2. nginx installation
1. Download nginx and related components
The Linux system is centos 6.5 64-bit, I switched directly to the root user Installation
Enter the user directory to download the program
Download related components
[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 it
[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
Enter the nginx directory and start
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
启动 [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 the nginx configuration file located in the conf folder in the nginx directory5. Enable external network access
In the Linux system, by default, all ports of the firewall iptables manager are enabled. Only the default remote connection port 22 is enabled and the others are closed. The 80 and so on we set above are also closed, so we need to first apply Open the portMethod 1Close the firewall directly, which has better performance but poor security. If there is a front-end firewall, you can use this method
关闭防火墙 [root@localhost ~]# service iptables stop 关闭开机自启动防火墙 [root@localhost ~]# chkconfig iptables off [root@localhost ~]# chkconfig --list|grep ipt
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
如果防火墙你依然启用,只是设置了启用端口,那我们访问81那个端口会发现无法访问,因为我并没有加入白名单
到此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;代表默认主页
这样配置完毕我们输入域名就可以访问到该站点了。
负载均衡功能往往在接收到某个请求后分配到后端的多台服务器上,那我们就需要upstream{}块来配合使用
upstream xxx{};upstream模块是命名一个后端服务器组,组名必须为后端服务器站点域名,内部可以写多台服务器ip和port,还可以设置跳转规则及权重等等 ip_hash;代表使用ip地址方式分配跳转后端服务器,同一ip请求每次都会访问同一台后端服务器 server;代表后端服务器地址 server{};server模块依然是接收外部请求的部分 server_name;代表外网访问域名 location / {};同样代表过滤器,用于制定不同请求的不同操作 proxy_pass;代表后端服务器组名,此组名必须为后端服务器站点域名 server_name和upstream{}的组名可以不一致,server_name是外网访问接收请求的域名,upstream{}的组名是跳转后端服务器时站点访问的域名
配置一下windows的host将我们要访问的域名aaa.test.com指向linux
因为硬件有限,我是将windows中的iis作为nginx的后端服务器,所以配置一下iis的站点域名
打开cmd再ping一下aaa.test.com确实指向linux系统了,再打开浏览器输入aaa.test.com会显示bbb这个站点就代表负载成功了。
The above is the detailed content of How to install and deploy Nginx in Centos6.5 64-bit. For more information, please follow other related articles on the PHP Chinese website!

NGINX can be used to serve files and manage traffic. 1) Configure NGINX service static files: define the listening port and file directory. 2) Implement load balancing and traffic management: Use upstream module and cache policies to optimize performance.

NGINX is suitable for handling high concurrency and static content, while Apache is suitable for dynamic content and complex URL rewrites. 1.NGINX adopts an event-driven model, suitable for high concurrency. 2. Apache uses process or thread model, which is suitable for dynamic content. 3. NGINX configuration is simple, Apache configuration is complex but more flexible.

NGINX and Apache each have their own advantages, and the choice depends on the specific needs. 1.NGINX is suitable for high concurrency, with simple deployment, and configuration examples include virtual hosts and reverse proxy. 2. Apache is suitable for complex configurations and is equally simple to deploy. Configuration examples include virtual hosts and URL rewrites.

The purpose of NGINXUnit is to simplify the deployment and management of web applications. Its advantages include: 1) Supports multiple programming languages, such as Python, PHP, Go, Java and Node.js; 2) Provides dynamic configuration and automatic reloading functions; 3) manages application lifecycle through a unified API; 4) Adopt an asynchronous I/O model to support high concurrency and load balancing.

NGINX started in 2002 and was developed by IgorSysoev to solve the C10k problem. 1.NGINX is a high-performance web server, an event-driven asynchronous architecture, suitable for high concurrency. 2. Provide advanced functions such as reverse proxy, load balancing and caching to improve system performance and reliability. 3. Optimization techniques include adjusting the number of worker processes, enabling Gzip compression, using HTTP/2 and security configuration.

The main architecture difference between NGINX and Apache is that NGINX adopts event-driven, asynchronous non-blocking model, while Apache uses process or thread model. 1) NGINX efficiently handles high-concurrent connections through event loops and I/O multiplexing mechanisms, suitable for static content and reverse proxy. 2) Apache adopts a multi-process or multi-threaded model, which is highly stable but has high resource consumption, and is suitable for scenarios where rich module expansion is required.

NGINX is suitable for handling high concurrent and static content, while Apache is suitable for complex configurations and dynamic content. 1. NGINX efficiently handles concurrent connections, suitable for high-traffic scenarios, but requires additional configuration when processing dynamic content. 2. Apache provides rich modules and flexible configurations, which are suitable for complex needs, but have poor high concurrency performance.

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

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.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version
Useful JavaScript development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
