星空网 > 软件开发 > ASP.net

手把手教你认识并搭建Nginx

手把手教你认识并搭建Nginx

Nginx (“engine x”) 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。 Igor 将源代码以类 BSD 许可证的形式发布。尽管还是测试版,但是,Nginx 已经因为它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名了。

一. Nginx 的优点:

作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率,这点使 Nginx 尤其受到虚拟主机提供商的欢迎。能够支持高达 50,000 个并发连接数的响应。

作为负载均衡服务器:Nginx 既可以在内部直接支持 Rails 和 PHP,也可以支持作为 HTTP代理服务器 对外进行服务。Nginx 用 C 编写, 不论是系统资源开销还是 CPU 使用效率都比 Perlbal 要好的多。

作为邮件代理服务器: Nginx 同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器)。

Nginx 安装非常的简单,配置文件 非常简洁,Bugs非常少的服务器: Nginx 启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够在 不间断服务的情况下进行软件版本的升级。

二. 安装Nginx过程(在CentOS上搭建):

  1. 安装nginx依赖的插件,建议通过yum进行在线安装。
    yum -y install pcre-devel openssl openssl-devel gcc+c-- Pcre-devel是支持读写(支持正则表达式的库)等插件 openssl是支持ssl证书插件
  2. 安装libevent(由于nginx采用的是epoll机制需要事件库的支持)
    [root@localhost~]# tar -zxvf libevent-2.0.16-stable.tar.gz -C /usr/local/src/ [root@localhost~]# cd /usr/local/src/libevent-2.0.16-stable/ [root@localhost libevent-2.0.16-stable]# ./configure --prefix=/usr/local/libevent [root@localhost libevent-2.0.16-stable]# make && make install [root@localhost libevent-2.0.16-stable]# cd /usr/local/libevent/ 为了系统能其他的程序能够调用libevent的头文件和库文件我们需要进行下面的操作: [root@localhost libevent]# ln -s /usr/local/libevent/include /usr/include/libevent [root@localhost libevent]# vim /etc/ld.so.conf.d/libevent.conf 加入文件内容如下: 手把手教你认识并搭建Nginx root@localhost libevent]# ldconfig 手把手教你认识并搭建Nginx
  3. 安装nginx过程
    解压并配置nginx包 #tar –zxvf nginx-1.6.2.tar.gz 生成新的目录nginx-1.6.2,进入该目录下,配置安装nginx需要的相关配置信息 #./configure --user=root --group=root --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-cc-opt='-O2' --with-cpu-opt=opteron 编译 #make 安装nginx #make install 检查nginx配置是否正确 #/usr/local/nginx/sbin/nginx -t 手把手教你认识并搭建Nginx 启动nginx #/usr/local/nginx/sbin/nginx 查看nginx启动状态 #ps –ef|grep nginx
  4. 到这里nginx的安装已经完成了,接下来添加nginx的代理服务

     user root; #工作进程,一般根据CPU核数来定 worker_processes 2; server {   listen   9457;   server_name localhost;   location / {     root  html;     index index.html index.htm;   }   #这里配上项目地址的分发   location /YourProject1/ {     proxy_pass  http://127.0.0.1:8080/YourProject1/;     proxy_set_header  Host    $host;     proxy_set_header  X-Forwarded-For    $remote_addr;      }   location /YourProject2/ {     proxy_pass  http://127.0.0.1:8090/YourProject2/;     proxy_set_header  Host    $host;     proxy_set_header  X-Forwarded-For    $remote_addr;      } }
  5. 重启nginx Killall ngnix #/usr/local/nginx/sbin/nginx

手把手教你认识并搭建Nginx
获取【下载地址】 




原标题:手把手教你认识并搭建Nginx

关键词:nginx

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

Instagram推出一系列直播活动!加码社交电商布局!:https://www.kjdsnews.com/a/704185.html
2021年黑五促销亚马逊鞋服珠宝数据回盘:https://www.kjdsnews.com/a/704186.html
亚马逊100多条热门Listing挂掉,卖家怒了:https://www.kjdsnews.com/a/704187.html
今日突发!亚马逊AWS出现故障,对卖家造成了这些影响...:https://www.kjdsnews.com/a/704188.html
Fanno已入驻卖家是这么评价的……:https://www.kjdsnews.com/a/704189.html
锁定4000亿新蓝海,2022“智能家居”红利期已来!:https://www.kjdsnews.com/a/705165.html
Lazada为优化购物体验,升级买家取消订单政策:https://www.kjdsnews.com/a/1836358.html
Lazada为优化购物体验,升级买家取消订单政策:https://www.goluckyvip.com/news/186219.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流