Nginx的安裝與配置

一、首先關閉linux的防火牆,查看linux防火牆博客 https://www.cnblogs.com/liuyi-clover/p/9755966.htmlhtml

二、給nginx配置安裝目錄vue

         mkdir /usr/local/nginx  linux

三、解壓已經上傳到nginx目錄中的壓縮包nginx

          cd /usr/local/nginxc++

          tar -zxvf nginx-1.16.0.tar.gzapi

四、執行 ./configure命令app

          cd nginx-1.16.0負載均衡

          yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel
          ./configureide

五、make 編譯spa

          編譯的過程是把各類語言寫的源碼文件,變成可執行文件和各類庫文件

          cd /usr/local/nginx/nginx-1.16.0
          make

六、make install安裝

           把這些編譯出來的可執行文件和庫文件複製到合適的地方

           make install

七、啓動nginx服務

           cd /usr/local/nginx/sbin
           ./nginx

八、看nginx服務是否啓動

           ps -ef|grep nginx

九、關閉nginx:
           pkill -9 nginx

十、備註nginx.conf配置文件(Vue項目)

worker_processes  4;
error_log  logs/error.log  notice;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    #Nginx服務配置,直接訪問localhost:8080便可打開dist訪問vue項目
    #Linux下更改root目錄爲 /usr/local/dist/;便可
    server {
        listen       8080;
        server_name  localhost;
    
        location / {
            root   C:/Users/Clover/Desktop/dist;
            index  index.html index.htm;
        }
        location /api {
            proxy_pass  http://106.12.140.159:8888/api;
        }
        location /bpi {
            proxy_pass  http://cache.video.iqiyi.com/jp;
        }
    }
}

 十一、nginx負載均衡經常使用配置

worker_processes  4;
error_log  logs/error.log  notice;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    
    upstream nacos{
        server 192.168.232.110:8848 weight=8;
        server 192.168.232.111:8848 weight=10;
    }
    
    server {
        listen       8080;
        server_name  localhost;
    
        location / {
            root   html;
            index  index.html index.htm;
        }

        location /nacos {
            proxy_pass  http://nacos;
        }
                
    }
}
相關文章
相關標籤/搜索