关于centOS 下nginx 安装配置及出现403的问题

安装及配置

   软件安装目录为 /usr/local

1.安装gcc gcc-c++依赖包  命令:yum install -y gcc gcc-c++

2.下载编译安装PCRE库  (下载之前请把目录却换至 /usr/local) 

     命令:

        cd /usr/local 

       wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz

       tar -zxvf pcre-8.33.tar.gz

       cd pcre-8.33

      ./configure

       make && make install

3.下载编译安装SSL库  (下载之前请把目录却换至 /usr/local) 

     命令:

        cd /usr/local 

        wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz

       tar -zxvf openssl-1.0.1j.tar.gz

       cd openssl-1.0.1j

      ./config

      make && make install

4.下载编译安装zlib依赖库(下载之前请把目录却换至 /usr/local) 

命令:

        cd /usr/local 

        wget http://zlib.net/zlib-1.2.11.tar.gz

       tar -zxvf zlib-1.2.11.tar.gz

       cd zlib-1.2.11

      ./configure

      make && make install

5.依赖包和环境都安装配置好之后接下来就需要安装nginx了 (一样需要把目录却换至 /usr/local) 

命令:

        cd /usr/local 

       wget http://nginx.org/download/nginx-1.8.0.tar.gz

      tar -zxvf nginx-1.8.0.tar.gz

      cd nginx-1.8.0

     ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module

     make && make install

     在进行make && make install 的时候会出现stop的情况(如下图) 如没有出现此问题请跳过(a,b,c步骤)

解决步骤:

  a.更新yum  yum update 更新完成后,先删除之前准备make的nginx包,然后重新解压一个。

  b.安装前置库  yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd-devel

  c.重新执行

    ./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module

     make && make install

就可以成功了。

此时您的nginx就已经安装完成了 

6.启动/停止/重启

  切换目录:cd /usr/local/nginx

  启动:./sbin/nginx

  停止:./sbin/nginx -s stop

 重启:./sbin/nginx -s reload

访问服务器IP 就可以出现nginx index页了。

7.403问题 

  问题重现:nginx进行了配置并且做了路由转发,转发地址为/root/html/

  重启后再次访问就出现了403的问题

  问题查询

    通过端口查看命令查看nginx是由什么用户启动的  然后再查看nginx.conf user

        ps -ef | grep nginx

    nginx 配置文件 /usr/local/nginx/conf/nginx.conf

       

 如果不一致 修改为一致 即可解决403问题 

留笔记

相关参考

https://cloud.tencent.com/developer/article/1498208

https://blog.csdn.net/cailongbiaoyuli/article/details/84348866

发布了2 篇原创文章 · 获赞 3 · 访问量 1509

猜你喜欢

转载自blog.csdn.net/duke645/article/details/104188890
今日推荐