Nginx的安装与卸载

有时候,我们需要单独安装nginx,来处理大量的下载请求。单独在Centos5安装nginx遇到的rewrite和HTTP cache错误解决办法:

wget http://nginx.org/download/nginx-0.8.33.tar.gz
tar -zxvf nginx-0.8.33.tar.gz 
cd nginx-0.8.33
./configure --prefix=/usr/local/nginx

 

安装Nginx时报错

./configure: error: the HTTP rewrite module requires the PCRE library.

安装pcre-devel解决问题
yum -y install pcre-devel

 

错误提示:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library.   You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.

解决办法:

yum -y install openssl openssl-devel

 

总结:

yum -y install pcre-devel openssl openssl-devel

./configure --prefix=/usr/local/nginx

make

make install

一切搞定

----------------------------------------------------------------卸载-------------------------------------------------------------

 

卸载:

删除nginx目录即可

rm -rf /opt/nginx

(rm -rf /usr/local/nginx)

如果配置了自启动,也需要删除

 

官方文档:

http://nginx.org/en/docs/

### 如何在树莓派上卸载并重新安装 Nginx 的操作指南 在树莓派上卸载并重新安装 Nginx 是一个常见的任务,尤其是在需要清理旧配置或解决安装问题时。以下是具体的操作步骤: #### 1. 卸载现有的 Nginx 首先,确保系统中已有的 Nginx 被完全卸载,包括其依赖项和配置文件。 运行以下命令以卸载 Nginx 及其相关组件: ```bash sudo apt-get purge nginx nginx-common nginx-full -y ``` 这一步会移除 Nginx 的核心包及其常用配置[^2]。 接着,删除可能残留的 Nginx 配置文件和其他数据: ```bash sudo rm -rf /etc/nginx /var/log/nginx /var/cache/nginx /var/www/html ``` #### 2. 更新软件包索引 在重新安装之前,建议更新系统的软件包索引以确保获取最新的软件版本: ```bash sudo apt-get update ``` #### 3. 安装 Nginx 重新安装 Nginx 可通过以下命令完成: ```bash sudo apt-get install nginx -y ``` 此命令将从默认的 Raspbian/Debian 源下载并安装最新版本的 Nginx[^2]。 #### 4. 启动并检查 Nginx 状态 安装完成后,启动 Nginx 服务并设置为开机自启: ```bash sudo systemctl start nginx sudo systemctl enable nginx ``` 验证 Nginx 是否正常运行: ```bash sudo systemctl status nginx ``` 如果一切正常,可以通过浏览器访问树莓派的 IP 地址(如 `http://<树莓派IP>`),查看默认的 Nginx 欢迎页面。 #### 5. 配置防火墙(如果启用) 如果树莓派启用了防火墙(如 `ufw`),需要允许 HTTP 和 HTTPS 流量: ```bash sudo ufw allow 'Nginx Full' sudo ufw reload ``` --- ### 注意事项 - 在执行上述操作前,请确保备份重要数据,尤其是 `/var/www/html` 目录中的内容。 - 如果使用了非标准的 Nginx 配置文件路径,请根据实际情况调整删除命令。 --- ### 示例代码:检查 Nginx 版本 可以使用以下命令检查当前安装Nginx 版本: ```bash nginx -v ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值