巅云智能建站平台搭建版(创业流派版)火爆上线,毕生受权!新增:文章智能收罗+全站真静态打包+都会分站+智能小法式+不法词过滤+H5自顺应+智能链词等功效功效概况
赞助文档Help

Linux情况下装置Nginx及其利用

一佰互联网站建造(www.taishanly.com) 宣布日期 2020-04-23 09:20:56 阅读数: 168

一、检查CentOS的版本

cat /etc/redhat-release

二、增加资本库

在 CentOS 体系上装置 Nginx ,得先去增加一个资本库:

vim /etc/yum.repos.d/nginx.repo
  [nginx]
  name=nginx repo
  baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
  gpgcheck=0
  enabled=1

三、装置nginx

yum -y install nginx


四、测试nginx设置装备摆设文件是不是准确

nginx -t

打印以下:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

五、CentOS7.0+ nginx完成遏制、启动、重启

systemctl stop nginx.service  
systemctl start nginx.service
systemctl restart nginx.service
systemctl status nginx.service

开机自启:

systemctl enable nginx.service

打消开机自启:

systemctl disable nginx.service

六、nginx.conf设置装备摆设示例

我的设置装备摆设:

user nginx;
worker_processes 4;

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"";

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

  sendfile    on;
  #tcp_nopush   on;

  keepalive_timeout 65;

  #gzip on;

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

  #设定负载平衡的办事器列表
  upstream pay_server {
    ip_hash;
    server 10.74.248.01:8088 max_fails=2 fail_timeout=2;
    server 10.74.248.02:8088 max_fails=2 fail_timeout=2;
  }

  upstream print_server {
    ip_hash;
    server 10.74.248.03:2001 max_fails=2 fail_timeout=2;
    server 10.74.248.04:2001 max_fails=2 fail_timeout=2;
  }

  upstream accss_door_server {
    ip_hash;
    server 10.74.248.05:2002 max_fails=2 fail_timeout=2;
    server 10.74.248.06:2002 max_fails=2 fail_timeout=2;
  }
  
  server {
    listen 80;
    server_name wab.kupu.ccoop.com.cn;
    location /invengo {
         proxy_pass http://pay_server;
         index index.jsp index.html index.htm;
    }
    location /invengo/epc {
         proxy_pass http://print_server;
         index index.jsp index.html index.htm;
    }
    location /invengo/print {
         proxy_pass http://print_server;
         index index.jsp index.html index.htm;
    }

    location /checkout {
         proxy_pass http://accss_door_server;
         index index.jsp index.html index.htm;
    }
    location /asset {
         proxy_pass http://accss_door_server;
         index index.jsp index.html index.htm;
    }
  }

经常利用的nginx.conf设置装备摆设:

user www www;
worker_processes 2;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid    logs/nginx.pid;
events {
  use epoll;
  worker_connections 2048;
}
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 65;
 # gzip紧缩功效设置
  gzip on;
  gzip_min_length 1k;
  gzip_buffers  4 16k;
  gzip_http_version 1.0;
  gzip_comp_level 6;
  gzip_types text/html text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
  gzip_vary on;
 
 # http_proxy 设置
  client_max_body_size  10m;
  client_body_buffer_size  128k;
  proxy_connect_timeout  75;
  proxy_send_timeout  75;
  proxy_read_timeout  75;
  proxy_buffer_size  4k;
  proxy_buffers  4 32k;
  proxy_busy_buffers_size  64k;
  proxy_temp_file_write_size 64k;
  proxy_temp_path  /usr/local/nginx/proxy_temp 1 2;
 # 设定负载平衡背景办事器列表 
  upstream backend { 
       #ip_hash; 
       server  192.168.10.100:8080 max_fails=2 fail_timeout=30s ; 
       server  192.168.10.101:8080 max_fails=2 fail_timeout=30s ; 
  }
 # 很主要的假造主机设置装备摆设
  server {
    listen    80;
    server_name itoatest.example.com;
    root  /apps/oaapp;
    charset utf-8;
    access_log logs/host.access.log main;
    #对 / 一切做负载平衡+反向代办署理
    location / {
      root  /apps/oaapp;
      index index.jsp index.html index.htm;
      proxy_pass    http://backend; 
      proxy_redirect off;
      # 后真个Web办事器能够经由过程X-Forwarded-For获得用户实在IP
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
      
    }
    #静态文件,nginx本身处置,不去backend要求tomcat
    location ~* /download/ { 
      root /apps/oa/fs; 
      
    }
    location ~ .*.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$  
    {  
      root /apps/oaapp;  
      expires   7d; 
    }
    location /nginx_status {
      stub_status on;
      access_log off;
      allow 192.168.10.0/24;
      deny all;
    }
    location ~ ^/(WEB-INF)/ {  
      deny all;  
    }
    #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;
    }
  }
 ## 别的假造主机,server 指令起头
}

以上便是本文的全数内容,但愿对巨匠的进修有所赞助,也但愿巨匠多多撑持网页设想。

一佰互联是天下着名建站品牌办事商,咱们有九年、网站建造、网页设想、php开辟和域名注册及假造主机办事经历,供给的办事更是天下着名。比来几年来还整合团队上风自立开辟了可视化多用户”“3.0平台版,拖拽排版网站建造设想,轻松完成pc站、手机微网站、小法式、APP一体化全网营销网站扶植 ,已胜利的为天下上百家收集公司供给自助建站平台搭建办事。

相干消息more

01
02月
让人感触感染“高峻上”,起首设想须要具有必然的冲

一:顺从「简略、通俗」 良多人会误觉得网站要用到良多的殊效,切忌良多应用动画、动画不宜偏激夸大(比方PPT里的百叶窗这类动画),顺从物体简... >>概况

10
04月
比来Dribbble 风行的配色气概是甚么?

Dribbble 是尽人皆知的设想社群网站,在网站中有良多人分享设想作品,相互交换或从其余设想获得灵感。固然也有不少网站应运而生,比方 Fr... >>概况

29
07月
企业建网站普通用甚么东西?

分享 对小我来讲,搭建博客网站能够利用wordp... >>概况

29
04月
基于preg_match_all收罗后数据处

1、利用curl完成站外收罗具体请参考我上一篇条记://www.taishanly.com/article/46432.htm2、编码转换起首经由过程查... >>概况

高端网站扶植

美工统筹SEO,为企业电子商务营销助力!

德律风:

023-85725751
建站

产物

域名注册 假造主机 云办事器 企业邮局
智能建站 APP打包 微站/小法式 创业平台
网站推行 媒体营销 智能收罗 AI机械人
400德律风 短信营销 店销机械人
私家定制 流派网站