Linux for CentOS 下的 nginx 绿色安装-超省心安装

1.我这里是nginx-1.13.0-1.x86_64 .rpm(点击下载)版本的。

2.安装nginx的相应环境。有些环境可能不必须,但是安装了,确保以防万一,多多益善

yum install gd-devel
yum install gcc-c++ 
yum -y install gcc gcc-c++ autoconf automake make
yum -y install zlib zlib-developenssl openssl-devel pcre pcre-devel
yum install libgd2-devel
yum install libpcre-devel
yum install libcurl-devel
yum install gd-devel

3.我再opt目录下建立了一个software文件夹,用来存放资源包的

   进入该目录  cd   /opt/software/  

   随之解压   rpm -ivh  nginx-1.13.0-1.x86_64 .rpm

4.这个时候,nginx的相关配置都在你/etc/nginx目录下

    根据自己的需要,修改nginx.conf

user nobody;
worker_processes auto;
worker_rlimit_nofile 102400;
pid /run/nginx.pid;

events {
        use epoll;
        worker_connections 10240;
        multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        types_hash_max_size 2048;
        server_tokens off;
        # allow the server to close connection on non responding client, this will free up memory
        reset_timedout_connection on;

        # number of requests client can make over keep-alive -- for testing environment
        keepalive_requests 1000;
        proxy_next_upstream error timeout invalid_header;
        proxy_intercept_errors on; 
        proxy_redirect off;
        proxy_set_header Host $host:$server_port;
        proxy_redirect http:// $scheme://;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Connection "";
        proxy_http_version 1.1;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

 #       ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
 #       ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##
        log_format main '$upstream_addr $scheme $http_host [$request_time|$upstream_response_time|$upstream_status] '
                  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for" $gzip_ratio';


        access_log /var/log/nginx/access.log main;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##
        gzip on;
        gzip_static on;
        gzip_buffers 16 8k;
        gzip_comp_level 6;
        gzip_http_version 1.1;
        gzip_min_length 256;
        gzip_proxied any;
        gzip_vary on;
        gzip_types
                text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
                text/javascript application/javascript application/x-javascript
                text/x-json application/json application/x-web-app-manifest+json
                text/css text/plain text/x-component
                font/opentype application/x-font-ttf application/vnd.ms-fontobject
                image/x-icon;
        gzip_disable "msie6";

        ##
        # Virtual Host Configs
        ##
        include /etc/nginx/http-conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
        include /etc/nginx/sites-available/*.conf;
}

stream {
        include /etc/nginx/stream-conf.d/*.conf;
        include /etc/nginx/stream-enabled/*;
}

此时,你可以把你的IP端口号写在这个配置里面,也可以写在这个下面

/etc/nginx/sites-available/*.conf;

这里我把我的IP端口就写在这里,命名叫做TestSite.conf
upstream upstream_10009 {
        #sticky;
        ip_hash;
        server 10.10.0.112:10009;
        server 10.10.0.113:10009;
        keepalive 64;
}
upstream upstream_10010 {
        sticky;
        server 10.10.0.112:10010;
        server 10.10.0.113:10010;
        keepalive 64;
}
upstream upstream_10020 {
        sticky;
        server 10.10.0.112:10020;
        server 10.10.0.113:10020;
        keepalive 64;
}
upstream upstream_10030 {
        sticky;
        server 10.10.0.112:10030;
        server 10.10.0.113:10030;
        keepalive 64;
}
server {
    listen 9000;
    #listen 443 ssl;
    #ssl_certificate /etc/nginx/SSL/dlcloudhis.xikang.com.pem;
    #ssl_certificate_key /etc/nginx/SSL/dlcloudhis.xikang.com.key;
    server_name localhost;

    location / {
        #proxy_buffer_size  128k;
        #proxy_buffers   32 32k;
        #proxy_busy_buffers_size 128k;
        proxy_redirect http:// $scheme://;
        proxy_pass http://upstream_10009/;
        add_header backenIP $upstream_addr;
        add_header backenCode $upstream_status;
    }
    
    location /TestOne/ {
                proxy_redirect http:// $scheme://;
                proxy_pass http://upstream_10010/;
        }

    location /TestTwo/ {
                #add_header backendIP $upstream_addr;
                #add_header backendCode $upstream_status;
                proxy_redirect http:// $scheme://;
                #proxy_send_timeout 120s;
                #proxy_read_timeout 120s;
                proxy_pass http://upstream_10020/;
        }

    location /TestThree/ {
                proxy_redirect http:// $scheme://;
                proxy_pass http://upstream_10030/;
        }

}
#------------------------------

#------------------------------

#------------------------------
upstream upstream_10060 {
    sticky;
    server 10.10.0.112:10060;
    server 10.10.0.113:10060;
    keepalive 64;
}

server {
    listen 10060;
    server_name localhost;
    location /myPet/ {
        proxy_redirect http:// $Scheme://;
        proxy_pass http://upstream_10060/;
    }
}
#------------------------------
upstream upstream_10072 {
    sticky;
    server 10.10.0.112:10072;
    server 10.10.0.113:10072;
    keepalive 64;
}
 
server {
    listen 10072;
    server_name localhost;
    location /myHome/ {
        proxy_redirect http:// $Scheme://;
        proxy_pass http://upstream_10072/;
    }
}
 

因为我的服务器项目需要传递Token,我使用的是 ip_hash 负载算法。

配置完毕之后,可以使用 可以用systemctl启动、重载、停止nginx

 例如:

               systemctl status nginx.service     #状态
               systemctl start   nginx.service      #开始
               systemctl stop   nginx.service      #停止

然后开始访问你的项目吧!此部署nginx是最省心的方法。

 

 

你可能感兴趣的:(Linux for CentOS 下的 nginx 绿色安装-超省心安装)