温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

分布式服务Nginx搭建以及部署配置方法

发布时间:2021-07-02 16:44:22 来源:亿速云 阅读:732 作者:chen 栏目:大数据

这篇文章主要讲解了“分布式服务Nginx搭建以及部署配置方法”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“分布式服务Nginx搭建以及部署配置方法”吧!

一. Nginx的部署及配置;

    1.检测系统的版本: centOS7

       CentOS 7,使用yum安装Nginx

       安装Nginx源

 rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

   安装该rpm后,我们就能在/etc/yum.repos.d/ 目录中看到一个名为nginx.repo 的文件。

安装Nginx

安装完Nginx源后,就可以正式安装Nginx了。

yum install -y nginx

以下是Nginx的默认路径:

(1) Nginx配置路径:/etc/nginx/
(2) PID目录:/var/run/nginx.pid
(3) 错误日志:/var/log/nginx/error.log
(4) 访问日志:/var/log/nginx/access.log
(5) 默认站点目录:/usr/share/nginx/html

事实上,只需知道Nginx配置路径,其他路径均可在/etc/nginx/nginx.conf 以及/etc/nginx/conf.d/default.conf 中查询到

常用命令

(1) 启动:

nginx

(2) 测试Nginx配置是否正确:

nginx -t

(3) 优雅重启:

nginx -s reload

(4) 查看nginx的进程号:

ps -ef |grep nginx

(5)nginx服务停止

nginx -s stop
kill -9 pid

编辑的nginx.conf配置文件如下

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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 $request_time $upstream_response_time';

    log_format log_wisecloud '{"project": "新云",'
                    '"@timestamp": "$time_local",'
                    '"remote_addr": "$remote_addr",'
                    '"request_host":"$http_host",'
                    '"request_api":"$uri",'
                    '"request_uri":"$request_uri",'
                    '"request_method": "$request_method",'
                    '"status": "$status",'
                    '"body_bytes_sent": "$body_bytes_sent",'
                    '"request_time": "$request_time",'
                    '"upstream_response_time": "$upstream_response_time",'
                    '"upstream_addr":"$upstream_addr",'
                    '"http_x_forwarded_for": "$http_x_forwarded_for",'
                    '"http_referrer": "$http_referer",'
                    '"http_user_agent": "$http_user_agent"}';

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

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    client_max_body_size 2048m;
    client_body_buffer_size 1024m;
    client_header_timeout 4800s;
    client_body_timeout 4800s;
    client_header_buffer_size 1280m;
    large_client_header_buffers 4 1280m;


    fastcgi_connect_timeout 3000s;
    fastcgi_send_timeout 3000s;
    fastcgi_read_timeout 3000s;
    fastcgi_buffer_size 1280k;
    fastcgi_buffers 2 2560k;
    fastcgi_busy_buffers_size 2560k;
    fastcgi_temp_file_write_size 2560k;
    fastcgi_ignore_client_abort on;

    proxy_connect_timeout   3000;
    proxy_send_timeout      3000;
    proxy_read_timeout      3000;
    proxy_ignore_client_abort on;

    gzip  on;
    gzip_http_version 1.0;
    gzip_min_length 1k;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/json application/x-www-form-urlencoded;

    include /etc/nginx/conf.d/*.conf;
}

######################  模块配置  ####################
test-80.conf

server {
    listen     80;
    server_name  xxxx.yyy.com;
    access_log /var/log/nginx/cloud-cn.log  log_cloud;
    ssl_certificate /etc/nginx/ssl/cloud-cn.coud.com.pem;
    ssl_certificate_key /etc/nginx/ssl/cloud-cn.cloud.com.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
    ssl_session_timeout  5m;
    ssl_prefer_server_ciphers   on;

  #location @router {
  #  rewrite ^.*$ /index.html last;
  #}

  location /api/ {
     proxy_pass  http://192.168.1.13:8083/;
     proxy_set_header Host $host:$server_port;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Real-PORT $remote_port;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_connect_timeout   600s;
     proxy_send_timeout      600s;
     proxy_read_timeout      600s;
     fastcgi_connect_timeout 600s;
     fastcgi_send_timeout    600s;
     fastcgi_read_timeout    600s;
  }

  location /config/ {
     proxy_pass  http://localhost:8082/;
     proxy_set_header Host $host:$server_port;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Real-PORT $remote_port;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  location /check.html {
     alias  /etc/nginx/health/check.html;
  }

  location / {
     alias  /home/html/dist/;
     try_files $uri $uri/ /index.html;
     index index.htm index.html index.php;
  }
}

############### https  443 模块配置###################

server {
    listen     80;
    server_name  xxx.yyy.com;
    access_log /var/log/nginx/name-cn.log  log_name;
    ssl_certificate /etc/nginx/ssl/test-cn.testeasy.com.pem;
    ssl_certificate_key /etc/nginx/ssl/test.test.com.key;
server {
    listen     80;
    server_name   xxx.yyy.com;
    access_log /var/log/nginx/test-cn.log  log_wisecloud;
    ssl_certificate /etc/nginx/ssl/test-cn.test.com.pem;
    ssl_certificate_key /etc/nginx/ssl/test.test.com.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
    ssl_session_timeout  5m;
    ssl_prefer_server_ciphers   on;

  #location @router {
  #  rewrite ^.*$ /index.html last;
  #}

  location /api/ {
     proxy_pass  http://192.168.1.13:8083/;
     proxy_set_header Host $host:$server_port;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Real-PORT $remote_port;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_connect_timeout   600s;
     proxy_send_timeout      600s;
     proxy_read_timeout      600s;
     fastcgi_connect_timeout 600s;
     fastcgi_send_timeout    600s;
     fastcgi_read_timeout    600s;
  }

  location /config/ {
     proxy_pass  http://localhost:8082/;
     proxy_set_header Host $host:$server_port;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Real-PORT $remote_port;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

  location /check.html {
     alias  /etc/nginx/health/check.html;
  }

  location / {
     alias  /home/html/dist/;
     try_files $uri $uri/ /index.html;
     index index.htm index.html index.php;
  }
}
 

感谢各位的阅读,以上就是“分布式服务Nginx搭建以及部署配置方法”的内容了,经过本文的学习后,相信大家对分布式服务Nginx搭建以及部署配置方法这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI