avatar

目录
Nginx 部署多个WEB服务

Centos7

本文主要以Nginx代理Django项目和gitbook服务为例

  1. 修改Nginx的配置文件nginx.conf

    我是用wget 源码下载的,不用yum下载的,配置文件有些误差,修改内容如下,主要是去掉server部分,

    http部分加上你要代理配置文件的地址

    Code
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    user root;
    worker_processes auto;
    error_log logs/error.log info;; # 错误日志
    pid /usr/local/nginx/logs/nginx.pid;

    events {
    worker_connections 1024;
    }

    http {
    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;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    # include /etc/nginx/conf.d/*.conf;
    include /etc/nginxconf/*.conf; # 自定义地址 可修改
    }
  2. 在我写服务配置文件的地址,添加我这俩个服务的配置

    Django的项目

    djangodemo.conf

    Code
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    server {
    listen 4000 ; # 监听的端口
    server_name build.2222.com; # 域名解析
    charset utf-8; #
    client_max_body_size 200m;
    access_log /var/log/nginx/git-access.log;
    error_log /var/log/nginx/git-err.log;
    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
    #静态文件如js,css的存放目录
    alias /home/myb/MyNotes/MyNotes/_book;
    }
    location / {
    proxy_pass http://0.0.0.1:8000; # 这里要配合启动文件使用
    proxy_redirect off;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }
    }

    gitbook

    gitbook.conf

    Code
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    server {
    listen 4000;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
    root /home/roc/mygitbook/_book; # 我gitbook静态网页的地址
    index index.html index.htm;
    }
    }
  3. 重启Nginx

    Code
    1
    nginx -s reload

    就可以访问我的俩个网址

    在浏览器上输入如下地址

    Django项目 访问网址 IP:8000

    gitbook 访问网址 IP:4000

    IP——>Centos 服务器的IP地址

文章作者: Jack-Roc
文章链接: http://jack-roc.top/2018/10/20/Nginxx/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Jack-Roc
打赏
  • 微信
    微信
  • 支付寶
    支付寶