Centos7
本文主要以Nginx
代理Django
项目和gitbook
服务为例
修改
Nginx
的配置文件nginx.conf
我是用
wget
源码下载的,不用yum
下载的,配置文件有些误差,修改内容如下,主要是去掉server
部分,在
http
部分加上你要代理配置文件的地址Code1
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
31user 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; # 自定义地址 可修改
}在我写服务配置文件的地址,添加我这俩个服务的配置
Django
的项目djangodemo.conf
Code1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21server {
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
Code1
2
3
4
5
6
7
8
9
10
11
12
13server {
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;
}
}重启
Nginx
Code1
nginx -s reload
就可以访问我的俩个网址
在浏览器上输入如下地址
Django
项目 访问网址IP:8000
gitbook
访问网址IP:4000
IP——>Centos 服务器的IP地址