麒麟海思Linux(Ubuntu)安裝編譯安裝Nginx


Nginx 的集群安裝配置,可從 http://nginx.org/en/download.html 網站,下載最新版本 Nginx。

本文版本是nginx-1.8.1.tar.gz。

1、下載nginx-1.8.1.tar.gz上傳至/home/nginx目錄下
cd home/nginx
tar xzvf nginx-1.8.1.tar.gz
2、進入 Nginx 解壓目錄,運行編譯安裝程序。
cd nginx-1.8.1
./configure --prefix=/home/nignx1.8.1 --with-http_stub_status_module     
#--prefix 為安裝目錄
make
make install
3、進入Nginx的conf目錄,根據需要更改監聽端口
cd conf
vi nginx.conf
將其中的listen       80;根據需要自行更改端口
4、進入 Nginx 的 sbin 目錄,運行 ./nginx –t。
cd /home/nginx1.8.1/sbin/
./nginx –t
5、打開瀏覽器訪問Nginx地址NginxIp:listenPort,如果出現下面頁面說明安裝成功。

 

6、停止或重啟Nginx。

停止 Nginx:#./nginx -s stop

Nginx重加載:#./nginx -s reload

 

Nginx下集群配置

進入Nginx的conf目錄,編輯nginx.conf文件,簡單配置內容如下:
#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 {
    use epoll; #linux 下采用 epoll
    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 backend { #負載
        #IP 負載
        ip_hash;
        server 192.168.0.1:8081 weight=1; #后台服務的 IP 及 http 端口
        server 192.168.0.2:8081 weight=1; #weight權重
    }

    server {
        #對外端口
        listen       8088;
        server_name  localhost;
        
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        location / {
            proxy_pass http://backend; #對應上面 upstream backend
            proxy_redirect off;
            #禁用緩存
            proxy_buffering off;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
        
        }
  
        #location / {
         #   root   html;
         #   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;
    #    }
    #}

}

 

注:Nginx更詳細配置說明請參考:http://nginx.org/en/docs/。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM