nginx 在lunix系統的安裝使用

1.由於Nginx依賴於gcc的編譯環境,須要安裝編譯環境來使Nginx可以編譯起來。php

yum install gcc-c++

2.Nginx的http模塊須要使用pcre來解析正則表達式,須要安裝pcrehtml

yum install -y pcre pcre-devel

3.安裝依賴的解壓包。nginx

yum install -y zlib zlib-devel

4.ssl 功能須要 openssl 庫c++

yum install -y openssl openssl-devel

5.下載nignx完成後,將Nginx壓縮包移動到Linux的待安裝目錄中,任意目前均可以正則表達式

例如我存放的壓縮包在/mnt/soft/目錄下面vim

 當前目錄下解壓Nginx:後端

tar -zxvf nginx-1.16.1.tar.gz

 

6.建立安裝目錄服務器

mkdir /usr/local/nginx

這個也是默認路徑,也能夠自定義路徑session

7.回到nginx解壓路徑app

cd /mnt/soft/nginx-1.6.1

8.執行編譯命令

#配置一下編譯的路徑,若是是默認路徑/usr/local/nginx的話,下面就能夠直接運行./configure就能夠了
./configure --prefix=/usr/local/nginx

#編譯安裝
make && make install

9配置nginx.conf

vim /usr/local/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 {
    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;
    #設定負載均衡的服務器列表
    upstream taishan {
        #weigth參數表示權值,權值越高被分配到的概率越大
        #下面表示137有3分之2概率,138有3分之1概率
        server 172.16.0.12:8082 weight=3;
        server 172.16.0.4:8082 weight=1;
    }

    #gzip  on;

    server {
        listen       8096;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://taishan;#請求轉向taishan定義的服務器列表
            proxy_set_header Host $host;#將請求頭轉發給後端服務器
            proxy_set_header X-Forward-For $remote_addr;#後端的Web服務器能夠經過X-Forwarded-For獲取用戶真實IP
            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;
    #    }
    #}

}
相關文章
相關標籤/搜索