CentOS5.8编译安装Nginx1.2.7

一、安装nginx相对较为简单,安装前确认已经安装了pcre,可通过rpm -q pcre查看本机安装版本。一般安装即可。若无安装直接yum install pcre安装下。

二、下载当前稳定版1.2.7
cd /tmp
wget http://nginx.org/download/nginx-1.2.7.tar.gz

tar -xvf nginx-1.2.7.tar.gz

cd nginx-1.2.7

三、正式安装

点击(此处)折叠或打开

  1. #安装Nginx
  2. tar -zxvf nginx-1.2.7.tar.gz
  3. cd nginx-1.2.7
  4. ./configure --user=www --group=www \
  5. --prefix=/usr/local/nginx \
  6. --sbin-path=/usr/local/nginx/sbin/nginx \
  7. --conf-path=/usr/local/nginx/conf/nginx.conf \
  8. --with-http_stub_status_module \
  9. --with-http_ssl_module \
  10. --with-pcre \
  11. --lock-path=/var/run/nginx.lock \
  12. --pid-path=/var/run/nginx.pid
  13. 编译完成没错误后,执行以下命令
  14. make && make install && cd ../
四、更改nginx配置信息

点击(此处)折叠或打开

  1. #更改配置
  2. vi /usr/local/nginx/conf/nginx.conf

  3. #修改一些参数,别直接替换文件,这只是一部分
  4. user www

  5. events {
  6.     use epoll;
  7.     worker_connections 1024;
  8. }
  9. listen 80;
  10. server_name localhost;
  11. index    index.html index.htm index.php;
  12. root      /var/www/html;

  13. location ~ .*\.(php|php5)?$ {
  14.             fastcgi_pass 127.0.0.1:9000;
  15.             fastcgi_index index.php;
  16.             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  17.             include fastcgi_params;
  18.         }

  19. #注意这里
  20. #$document_root$fastcgi_script_name;
  21. #检测配置文件
  22. /usr/local/nginx/sbin/nginx -t

  23. #提示表示成功
  24. #nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  25. #nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

  26. #开启Nginx
  27. /usr/local/nginx/sbin/nginx
  28. #平滑重启Nginx
  29. /usr/local/nginx/sbin/nginx -s reload

  30. #添加开机启动
  31. vi /etc/rc.d/rc.local
  32. #最后一行加入
  33. /usr/local/nginx/sbin/nginx &
五、测试nginx及php是否可用

点击(此处)折叠或打开

  1. vi /var/www/html/index.php
  2. #新建index文件,输入
  3. <?php
  4. phpinfo();
  5. ?>
如果出现phpinfo界面,查看显示信息无异常,说明nginx跟php配置都成功。

这样就完成了nginx的安装配置。下一步就该进行zend安装了。
cd打开 淘宝销量排行榜,有好的建议可提供~
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是centos7.9编译安装nginx的步骤: 1. 安装编译nginx所需的依赖库: ``` yum install -y gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre pcre-devel libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxslt libxslt-devel gd gd-devel perl perl-devel perl-ExtUtils-Embed ``` 2. 下载nginx源码包: 可以到官网(https://nginx.org/en/download.html)下载最新的稳定版nginx源码包。 3. 解压源码包: ``` tar zxvf nginx-xxx.tar.gz ``` 4. 进入nginx源码目录,执行以下命令进行编译安装: ``` ./configure --with-http_stub_status_module --with-http_ssl_module make && make install ``` 其中,--prefix参数指定nginx安装目录,--with-http_stub_status_module参数启用状态页模块,--with-http_ssl_module参数启用SSL加密支持。 5. 配置nginx: 进入/usr/local/nginx/conf目录,编辑nginx.conf文件,进行配置。这里给出一个简单的配置文件示例: ``` user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /usr/local/nginx/conf/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root /usr/local/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/local/nginx/html; } } server { listen 443 ssl; server_name localhost; ssl_certificate /usr/local/nginx/conf/server.crt; ssl_certificate_key /usr/local/nginx/conf/server.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root /usr/local/nginx/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/local/nginx/html; } } } ``` 其中,listen参数指定监听端口,server_name参数指定域名,root参数指定网站根目录,ssl_certificate和ssl_certificate_key参数指定SSL证书和私钥文件路径。 6. 启动nginx: 进入/usr/local/nginx/sbin目录,执行以下命令启动nginx: ``` ./nginx ``` 7. 检查nginx是否启动成功: 执行以下命令查看nginx进程是否存在: ``` ps -ef | grep nginx ``` 执行以下命令检查nginx监听的端口是否打开: ``` netstat -tlnp | grep nginx ``` 如果输出类似以下内容,则说明nginx已经成功安装并启动: ``` tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN xxxx/nginx tcp 0 0 :::443 :::* LISTEN xxxx/nginx ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值