ningx 安装

如果服务器之前安装过 ningx 没安装成功可以先卸载之后再安装,卸载的步骤如下:

  1. 输入以下的命令全局查找 ningx 相关的文件:sudo find / -name nginx* 如果出现下图所示的情况则说明已经安装过ningx,如果什么也没有出现则证明没有安装过。

     ningx 安装

    2. 如果安装过ningx 执行命令 sudo rm -rf file 此处跟查找出来的nginx文件  逐个删除文件或者

        执行 sudo rm -rf file /usr/local/nginx* 全部和ningx相关的文件 (/usr/local/nginx 为公共的目录,* 代表全部)。

    3. 删除过后再输入步骤1的命令验证一下是否成功,如果出现下图所示的情况则说明卸载成功:

       ningx 安装

卸载之后就可以重新安装啦,安装的步骤如下:

1. 执行以下的命令下载ningx的安装包:

wget https://public-storage-bucket.oss-cn-beijing.aliyuncs.com/software/nginx-1.13.11.tar.gz

2.执行以下命令 检查服务器是否有c++编译环境:

 yum -y install gcc

yum -y install gcc-c++

yum install make

如果没有就会自动安装

3. 执行以下命令 安装 pre 和 pcre-devel  :因为 Nginx的Rewrite模块和HTTP核心模块会使用到PCRE正则表达式语法

 yum -y install pcre pcre-devel 我的服务器已经安装过啦 所以会出现下面的情况,如果没有安装过就会自动安装了

ningx 安装

4.执行以下命令 安装zlib :因为 zlib 库提供了开发人员的压缩算法,在Nginx的各种模块中需要使用gzip压缩

yum install -y zlib zlib-devel 我的服务器已经安装过啦 所以会出现下面的情况,如果没有安装过就会自动安装了

ningx 安装

5.安装 OpenSSL:为了让ningx支持https 协议

yum install -y openssl openssl-devel 我的服务器已经安装过啦 所以会出现下面的情况,如果没有安装过就会自动安装了

ningx 安装

6. 解压ningx安装包

tar -xvf 安装包名 解压安装包

ningx 安装

解压后会在local文件夹下出现下图所示的文件夹,证明解压成功啦

ningx 安装

7. 进入解压后的文件夹进行配置 执行命令 ./configure 如果出现下图所示的情况则证明配置成功,如果没有成功可以看看是不是上边哪个安装步骤没有安装对

ningx 安装

8. 在当前目录下输入 make 命令编译,如果出现下图所示的情况则说明编译成功

ningx 安装

9. 编译成功后输入 make install 进行安装,如果出现下图所示的情况则说明安装成功

ningx 安装

10. 如果安装成功后 会在目录下出现一个ningx的文件夹,如下图所示:

ningx 安装

11. 进入 /usr/local/nginx/conf 文件夹 修改ningx的配置文件 


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;
	
	 upstream xxxx.com {
        server 127.0.0.1:8083;
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   html;
			proxy_connect_timeout   3;  
            proxy_send_timeout      30;  
            proxy_read_timeout      30;  
            proxy_pass http://xxxx.com;
           #index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

 12. 使用命令 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 启动

 13. 使用命令 ps aux|grep nginx 查看nginx的进程,如果启动成功 则会出现下图所示的情况:

ningx 安装

ningx 重启的命令:/usr/local/nginx/sbin/nginx -s reload

这样就可以用你的域名进行访问啦