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 绿色安装-超省心安装的更多相关文章

  1. Ubuntu/CentOS下编译Nginx最基本参数

    Ubuntu/CentOS下编译Nginx安装基本参数,做个记录: groupadd www useradd -g www www ./configure --user=www --group=www ...

  2. 【Linux】CentOS下升级Python和Pip版本全自动化py脚本

    [Linux]CentOS下升级Python和Pip版本全自动化py脚本 CentOS7.6自带py2.7和py3.6 想要安装其它版本的话就要自己重新下载和编译py其它版本并且配置环境,主要是软链接 ...

  3. centos下 Apache、php、mysql默认安装路径

    centos下 Apache.php.mysql默认安装路径 http://blog.sina.com.cn/s/blog_4b8481f70100ujtp.html apache: 如果采用RPM包 ...

  4. linux和mac下的nginx和php的安装

    linux版本相关文档:http://www.nginx.cn/231.html 一.安装php 1.下载包,这里以php 5.3.10为例 2.执行下面shell命令 注意:下面配置的命令中第一行 ...

  5. Linux(CentOS)下设置nginx开机自动启动(2个办法)

    首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令: vim /etc/init.d/nginx 在脚本中添加如下命令: #!/bin/sh # # nginx - ...

  6. linux(centos)下安装git并上传代码些许步骤(亲自验证过的步骤)

     曾经听说了好多次github,但直到近期才第一次学习使用github来托管自己在linux下的代码! 说实话.我自己在使用的时候从网上查了好多教程.但总认为难以掌握(步骤过于繁琐),自己操作的时候还 ...

  7. 服务器学习--Linux、CentOS下安装zip与unzip指令

    Linux下安装zip解压功能 Linux服务器上一般默认没是没有有安装zip命令 安装zip指令 apt-get install zip 或  yum install zip 输入zip OK li ...

  8. centos 7.0 nginx 1.7.9成功安装过程

    centos 7.0根目录 的目录构成 [root@localhost /]# lsbin dev home lib64 mnt proc run srv tmp varboot etc lib me ...

  9. (转) centos 7.0 nginx 1.7.9成功安装过程

    centos 7.0根目录 的目录构成 [root@localhost /]# lsbin dev home lib64 mnt proc run srv tmp varboot etc lib me ...

随机推荐

  1. C#语法糖系列 —— 第二篇:聊聊 ref,in 修饰符底层玩法

    自从 C# 7.3 放开 ref 之后,这玩法就太花哨了,也让 C# 这门语言变得越来越多范式,越来越重,这篇我们就来聊聊 ref,本质上来说 ref 的放开就是把 C/C++ 指针的那一套又拿回来了 ...

  2. 如何实现 antd table 自动调整可视高度(纵向滚动条,scrollY)

    一.事情的起因 最近在做的项目中有大量的表格,正常的表格高度是没有限制的,数据量很大的时候会出现表格内容以及分页信息超出可视窗口, 为了查看超出的部分就需要滚动页面但是这样就会把查询条件等信息滚出可视 ...

  3. 初次接触Java感受

    认真开始研究了idea后端开发环境 感触很深,突然觉得自己不能再一天的颓废下去,认真找点事情做一做,毕竟自己还是一张白纸,趁着自己年纪轻轻 经过一周的摸索自己努力了还不够,心里多么渴望自己身边的人能够 ...

  4. 搭建PWN学习环境

    环境清单 系统环境 Ubuntu22.04 编写脚本 pwntools ZIO 调试 IDA PRO gdb pwndbg ROP工具 checksec ROPgadget one_gadget Li ...

  5. WSL与Windows环境共享

    Reference 更多cmd.exe帮助参考 cmd_helps WSL备份及windows Docker安装 WSL安装维护 在使用wsl时,总是需要执行windows的cmd,但是windows ...

  6. mysql忘记root密码实现免密登录

    1.配置my.cnf文件,跳过授权表: skip-grant-tables 2.重启mysqld服务 3.z直接mysql登录 4.use mysql这个数据库 5.设置密码: update user ...

  7. 485. Max Consecutive Ones - LeetCode

    Question 485. Max Consecutive Ones Solution 题目大意:给一个数组,取连续1的最大长度 思路:遍历数组,连续1就加1,取最大 Java实现: public i ...

  8. [BJOI2014]想法

    参考 P4581传送门 题意:给DAG,问每个点可以由多少个叶子到达. 思路: 随机化!!(题面有提示) 这道题利用在一个范围内随机的数期望均分范围的性质. 直接每个叶子在\([0,Max\_Rand ...

  9. 1个程序员单干之:怎样给我的升讯威在线客服系统编写堪比 MSDN 的用户手册

    本系列文章详细介绍使用 .net core 和 WPF 开发 升讯威在线客服与营销系统 的过程. 免费在线使用 & 免费私有化部署:https://kf.shengxunwei.com 视频实 ...

  10. 【原创】项目三Raven-2

    实战流程 1,C段扫描,并发现目标ip是192.168.186.141 nmap -sP 192.168.186.0/24 扫描目标主机全端口 nmap -p- 192.168.186.141 访问8 ...