在linux下配置nginx

安装教程

CentOS 7 下安装 Nginx - 四海骄阳 - 博客园 (cnblogs.com)

 

三、安装所需插件
3.1.安装gcc
yum install -y gcc
3.2安装pcre、pcre-devel
yum install -y pcre pcre-devel
3.3安装 zlib
yum install -y zlib zlib-devel
3.4安装openssl
yum install -y openssl openssl-devel
3.5安装wget
yum install -y wget
3.6安装make
yum -y install gcc automake autoconf libtool make
3.7安装g++
yum install gcc gcc-c++
四、安装nginx
4.1下载nginx安装包
wget http://nginx.org/download/nginx-1.18.0.tar.gz
4.2.把压缩包解压到/usr/local/
tar -zxvf nginx-1.18.0.tar.gz -C /usr/local/
4.3切换到cd /usr/local/nginx-1.18.0/
执行3个命令
./configure --with-http_stub_status_module --with-http_ssl_module --with-stream --with-stream_ssl_module
make
make install
五、配置nginx
5.1切换到/usr/local/nginx/conf
vi nginx.conf

按上图红框内添加内容(其中 192.168.240.1和192.168.240.129是双机热备的服务器IP)
详细文件如下:


5.2 启动nginx服务
切换目录到/usr/local/nginx/sbin下面
启动nginx 命令:
./nginx

修改配置文件:

#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;
}

stream{
    upstream tcp_6000{
        server 192.168.240.1:6000;
        server 192.168.240.129:6000 backup;
    }

    server{
        listen 6000 so_keepalive=on;
        proxy_connect_timeout 10s;
        proxy_timeout 24h;
        proxy_pass tcp_6000;
    }

}

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 ls{
        server 192.168.240.1:80;
        server 192.168.240.129:80 backup;
    }

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://ls;
        }

        #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;
    #    }
    #}

}

遇到问题

unknown directive “stream” in /usr/local/nginx

 

posted @ 2021-09-21 10:18  当年小清新  阅读(737)  评论(0编辑  收藏  举报