欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Nginx部署与配置  

程序员文章站 2024-03-13 13:14:57
...

1.安装c++编译环境 
yum install -y gcc-c++

2.安装zlib和pcre. 
到官网上下载最新的包,用tar zxvf解压后,在文件夹内运行./configure &&make &&make install。

3.安装nginx 
到官网上下载最新的包,用tar zxvf解压后,在文件夹内运行./configure &&make &&make install。安装过程中可能会遇到./configure没有权限的情况,使用命令chmod +x configure来解决。

4.启动 
/usr/local/nginx/sbin/nginx

5.热加载配置 
/usr/local/nginx/sbin/nginx -s reload

Nginx配置 
编辑/usr/local/nginx/conf/nginx.conf即可。

负载均衡的配置文件:

events {
     use epool;
    worker_connections  51200;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    #负载均衡
    upstream cu.com{
        server 10.10.206.175:8888;
        server 10.10.206.174:8888;
   }
   server {
        listen       80;
        server_name  cu.com;
        location / {
        proxy_pass http://cu.com;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }}
}

静态文件服务器配置:

events {
     use epool;
    worker_connections  51200;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
   server {
         listen       8001;
        server_name  localhost;
    root /home/release;
    location / {
        autoindex on;
        autoindex_exact_size on;
        autoindex_localtime on;
    }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }}
}

sudo ./configure --with-pcre=/home/parallels/Downloads/pcre-8.40 --with-openssl=/home/parallels/Downloads/openssl-1.0.2k --with-stream --with-stream_ssl_module --with-http_ssl_module --with-http_v2_module --with-threads --add-module=/home/parallels/Downloads/nginxmodel/echo-nginx-module-0.60


可以解决error: You need a C++ compiler for C++ support的问题

yum install -y gcc gcc-c++