腾讯云服务安装nginx

1.安装依赖,如果已经安装了依赖,则跳过

yum -y install gcc gcc-c++ wget net-tools pcre-devel zlib-devel openssl-devel

2.下载并解压安装包

#进入常用文件夹
cd /usr/local/src/

#下载源码
wget http://nginx.org/download/nginx-1.7.12.tar.gz

#解压
tar zxvf nginx-1.7.12.tar.gz

#进入目录
cd nginx-1.7.12

3.安装

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

在这部会出现一些错误,一些错误解决方法如下:

 ./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-devel解决问题   : yum -y install pcre-devel 

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using –without-http_gzip_module
option, or install the zlib library into the system, or build the zlib 
library statically from the source with nginx by using –with-zlib=<path> option.

则需要安装“zlib-devel”即可 : yum install -y zlib-devel 

4.继续安装

#编辑   

make

#查看是否有错误  

echo $?    //显示0则成功 其他数组则失败

#安装

make install

5.启动

# 查看 Nginx 版本
nginx -v
# 查看 Nginx 安装目录
rpm -ql nginx
# 启动 Nginx
service nginx start

# 重启 Nginx
service nginx restart

6.配置项目

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
       # root         /usr/share/nginx/html/web;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        #配置静态图片访问地址 

         location   /images {  //图片访问前缀
             alias  /usr/share/nginx/html/server/images/;  //图片存放路径
             autoindex on;
        }

        location   / {   
              root  /usr/share/nginx/html/web;  //项目存放路径
              index index.html;
        } 

当项目为单页面时,浏览器刷新后报404,下面是解决办法:

location / {
            root   /mydata/transfer/html/helper/dist;
            index  index.html index.htm;
            try_files  $uri $uri/ /index.html;
        }

 7.查看项目

 

注意:可能在访问图像的时候会宝禁止访问错误‘forbid’问题,这时候要对图像的存放文件夹修改访问权限

#进入图像存放文件夹

cd  xx/xx/xx/ 

# 修改访问权限,加入-R 参数,就可以将读写权限传递给子文件夹,讲解权限操作的博客文章:https://blog.csdn.net/u013197629/article/details/73608613可以参考下。

chmod -R 777  /usr/share/nginx/html/server/images

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值