Linux下安装nginx

时间:2019-04-12
本文章向大家介绍Linux下安装nginx,主要包括Linux下安装nginx使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1.whereis nginx

  首先查看服务器上是否已经安装过nginx,如果没有,继续。

2.cd usr/local

3. 安装依赖

   yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake

   yum -y install wget httpd-tools vim
   yum -y install zlib zlib-devel

4. 下载tar包(nginx

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

5. 解压

tar -xvf nginx-1.14.2.tar.gz

6. 安装(cd nginx-1.13.7)

 mkdir nginx
./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf
make && make install(make->编译,make install->安装)

 注意:

  1)运行./configure报错: permission denied,

          说明文件不可执行,需要赋权:chmod +x configure

  2)运行make报错: make:*** No rule to make target `build', needed by `default'.  Stop.

           yum update->删除现有的nginx解压的文件夹,重新解压

      3) 运行make install报错: 是同一个文件

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

7. 启动

   cd /usr/local/nginx/sbin

   运行./nginx

8.  如果访问不到,请确认服务器的该端口是否开启。

9. nginx.conf配置文件

server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/dist;
            index  index.html index.htm;
        }
  }
  server {
        listen       8082;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html/build;
            index  index.html index.htm;
        proxy_pass http://localhost:8080;
        }
  }

10.重启nginx

   kill -HUP pid

11.查看nginx全部进程

   ps -ef | grep nginx(e:全部进程,f:全格式)