nginx服务器安装及部署

本文详细介绍如何在Linux环境下安装Nginx,并提供了解决安装过程中常见错误的方法。此外,还介绍了如何配置Nginx来托管一个简单的网站。

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

一 、环境准备

  1. 下载nginx 

下载地址:http://nginx.org/en/download.html  

 2.上传到虚拟机上,并解压

   tar-zxvf nginx-1.8.1.tar.gz

3.安装准备插件

yum -y install pcre-devel openssl openssl-devel

二 、安装nginx

 1.进入nginx目录并输入以下命令进行配置:

	./configure --prefix=/usr/local/nginx --add-module=/usr/local/fastdfs-nginx-module-master/src
 配置成功后会看到如下信息: 
   			
 2.进行编译安装,依次执行以下命令:
	make
	make install

安装完成后,我们在我们指定的目录/usr/local/nginx中就可以看到nginx的安装目录了: 

三 、配置文件的修改

1. 进入nginx安装目录的conf目录下,修改nginx.conf文件,在一个server{}中添加 一个location 部分配置代码如下

       user root; //此处写在最上方
root@ubuntu:/usr/local/nginx/conf# vi nginx.conf
  server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
       
//以下为要添加的内容
location /hello/ {
            root   /usr/local/helloWorld/;
            autoindex on;
        }
    }

2. 在nginx安装目录的html目录中新建一个 与 location中 image同名的image目录,虽然该目录里面什么也没有,
      在/usr/local/helloWorld/hello/中我们放一张图片1.jpg上去,重启nginx服务,就可以通过 localhost:80/image/1.jpg访问了
root@ubuntu:/usr/local/nginx/html# mkdir hello root@ubuntu:/usr/local/nginx/html# mkdir /usr/local/helloWorld/hello #放一张照片上去# root@ubuntu:/usr/local/nginx/html# cd  /usr/local/helloWorld/hello root@ubuntu:/usr/local/helloWorld/hello# ls 1.jpg root@ubuntu:/usr/local/helloWorld/hello#
3.启动nginx

   root@ubuntu:/usr/local/nginx/sbin# ./nginx 

**********************************************************

安装Nginx时报错 1.错误提示./configure:  error: the HTTP rewrite module requires the PCRE library. 安装pcre-devel解决问题 yum -y install pcre-devel 2.错误提示:./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 3.错误提示:error: the HTTP gzip module requires the zlib library 解决办法 yum install -y zlib-devel

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值