centos下安装nginx

本文详细记录了在 CentOS 系统上安装 Nginx 1.9.4 的过程,包括解决依赖问题、升级 Nginx 版本以及添加对 uWSGI 的支持。遇到的错误如 PCRE 库缺失和多线程不支持等问题,通过安装 pcre-devel 解决,并成功配置了 Nginx 的 aio threads 功能。同时,文章还介绍了如何使用 uwsgi 参数启动服务,并展示了 Nginx 的状态监控页面。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

centos下安装nginx


[root@iZ258gu0zkwZ tmp]# wget http://nginx.org/download/nginx-1.9.4.tar.gz
[root@iZ258gu0zkwZ tmp]# tar zxvf nginx-1.9.4.tar.gz 
[root@iZ258gu0zkwZ tmp]# cd nginx-1.9.4
[root@iZ258gu0zkwZ nginx-1.9.4]# ./configure --prefix=/opt/nginx --with-http_stub_status_module
出错:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.


安装pcre,可提示已是最新版本:
[root@iZ258gu0zkwZ nginx-1.9.4]# yum install pcre
Loaded plugins: security
Setting up Install Process
Package pcre-6.6-9.el5.i386 already installed and latest version
Nothing to do


现在是需要1.7.11以上的支持多线程模型的nginx版本,直接用yum查看nginx版本是0.8几,如下处理:
[root@iZ258gu0zkwZ nginx-1.9.4]# rpm -ivh http://nginx.org/packages/centos/5/i386/RPMS/nginx-1.8.0-1.el5.ngx.i386.rpm 
Retrieving http://nginx.org/packages/centos/5/i386/RPMS/nginx-1.8.0-1.el5.ngx.i386.rpm
warning: /var/tmp/rpm-xfer.Zua6AN: Header V3 RSA/SHA1 signature: NOKEY, key ID 7bd9bf62
Preparing...                ########################################### [100%]
   1:nginx                  ########################################### [100%]
----------------------------------------------------------------------


Thanks for using nginx!


Please find the official documentation for nginx here:
* http://nginx.org/en/docs/


Commercial subscriptions for nginx are available on:
* http://nginx.com/products/


----------------------------------------------------------------------
[root@iZ258gu0zkwZ nginx-1.9.4]# yum info nginx
Loaded plugins: security
Installed Packages
Name       : nginx
Arch       : i386
Version    : 1.8.0
Release    : 1.el5.ngx
Size       : 746 k
Repo       : installed
Summary    : High performance web server
URL        : http://nginx.org/
License    : 2-clause BSD-like license
Description: nginx [engine x] is an HTTP and reverse proxy server, as well as
           : a mail proxy server.




再执行安装:
[root@iZ258gu0zkwZ nginx-1.9.4]# yum install nginx
Loaded plugins: security
Setting up Install Process
Package matching nginx-0.8.55-6.el5.i386 already installed. Checking for update.
Nothing to do


先删除:
[root@iZ258gu0zkwZ nginx-1.9.4]# yum -y remove nginx
Loaded plugins: security
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package nginx.i386 0:0.8.55-6.el5 set to be erased
--> Finished Dependency Resolution


Dependencies Resolved


==================================================================================================================================================================================
 Package                                 Arch                                   Version                                         Repository                                   Size
==================================================================================================================================================================================
Removing:
 nginx                                   i386                                   0.8.55-6.el5                                    installed                                   936 k


Transaction Summary
==================================================================================================================================================================================
Remove        1 Package(s)
Reinstall     0 Package(s)
Downgrade     0 Package(s)


Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Erasing        : nginx                                                                                                                                                      1/1 


Removed:
  nginx.i386 0:0.8.55-6.el5                                                                                                                                                       


Complete!


重新安装,好像版本就对了:
[root@iZ258gu0zkwZ nginx-1.9.4]# whereis nginx
nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx
[root@iZ258gu0zkwZ nginx-1.9.4]# nginx -v
nginx version: nginx/1.8.0




修改nginx.conf文件,增加uwsgi的支持:
     31     server {
     32         listen       80;
     33         server_name  localhost;
     34 
     35         #charset koi8-r;
     36 
     37         #access_log  logs/host.access.log  main;
     38 
     39         location / {
     40             #root   html;
     41             #index  index.html index.htm;
     42             #aio threads;
     43             include uwsgi_params;
     44             uwsgi_pass 127.0.0.1:9000;
     45             uwsgi_param UWSGI_CHDIR /var/www/apps/vpoker;
     46             uwsgi_param UWSGI_SCRIPT webpy-vpoker;
     47         }
     48     }








************************************************************************************************************************************************************************************************************************************
安装uwsgi
************************************************************************************************************************************************************************************************************************************
安装pip
[root@iZ258gu0zkwZ tmp]# wget https://bootstrap.pypa.io/get-pip.py --no-check-certificate
[root@iZ258gu0zkwZ tmp]# python get-pip.py 


安装uwsgi
[root@iZ258gu0zkwZ tmp]# pip install uwsgi
[root@iZ258gu0zkwZ uwsgi]# uwsgi --version
2.0.11.1


启动uwsgi
[root@iZ258gu0zkwZ uwsgi]# uwsgi --socket :9000 --plugins=python --daemonize /var/log/uwsgi/uwsgi.log
open("./python_plugin.so"): No such file or directory [core/utils.c line 3675]
!!! UNABLE to load uWSGI plugin: ./python_plugin.so: cannot open shared object file: No such file or directory !!!




在浏览器中输入主机地址,可以正常通过webpy访问了!




************************************************************************************************************************************************************************************************************************************
编译安装nginx
************************************************************************************************************************************************************************************************************************************
[root@iZ258gu0zkwZ vpoker]# nginx -s reload
nginx: [emerg] "aio threads" is unsupported on this platform in /etc/nginx/nginx.conf:42
不支持多线程模式,而现在需要用到这个特性,不确定到底是不是系统问题,重新带参数编译一下nginx


[root@iZ258gu0zkwZ tmp]# wget http://nginx.org/download/nginx.1.9.4.tar.g
[root@iZ258gu0zkwZ tmp]# tar zxvf nginx-1.9.4.tar.gz
[root@iZ258gu0zkwZ tmp]# cd nginx-1.9.4


[root@iZ258gu0zkwZ nginx-1.9.4]# ./configure --prefix=/usr/local/nginx --with-threads --with-http_stub_status_module
出错:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.


解决:
[root@iZ258gu0zkwZ nginx-1.9.4]# yum -y install pcre-devel


再次执行./configure,成功:
Configuration summary
  + using threads
  + using system PCRE library
  + OpenSSL library is not used
  + md5: using system crypto library
  + sha1: using system crypto library
  + using system zlib library


  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"




编译安装:
make
make install


[root@iZ258gu0zkwZ nginx-1.9.4]# cd /usr/local/nginx/sbin
[root@iZ258gu0zkwZ sbin]# ./nginx -v
nginx version: nginx/1.9.4
[root@iZ258gu0zkwZ sbin]# ./nginx -V
nginx version: nginx/1.9.4
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-55)
configure arguments: --prefix=/usr/local/nginx --with-threads --with-http_stub_status_module


这次在nginx.conf中增加aio threads,重新加载没有出错!




nginx配置状态,修改nginx.conf文件:
     54         location /nginx_status
     55         {
     56                 stub_status on;
     57                 access_log off;
     58                 #allow 127.0.0.1;
     59                 #deny all;
     60         }
 
 通过浏览器访问http://youip/nginx_status进行查看,如下:
 Active connections: 2 
server accepts handled requests
 28 28 38 
Reading: 0 Writing: 1 Waiting: 1 


还可以用如下方式查看:
[root@iZ258gu0zkwZ sbin]# netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
ESTABLISHED 57
TIME_WAIT 4






ImportError: No module named webpy-vpoker
unable to load app 0 (mountpoint='') (callable not found or import error)
--- no python application found, check your startup logs for errors ---
[pid: 17394|app: -1|req: -1/3] 202.108.36.107 () {46 vars in 819 bytes} [Thu Aug 20 16:37:01 2015] GET /test => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)
碰到这问题的时候一定要仔细看,一定是模块名字写错了!!!




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值