centos7配置多个nginx
1. 前言
本文假设你有centos基础与django基础,较为简略抱歉,但原理十分简单只是简单做个笔记
2. 创建Django


3.更改nginx
user root;
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"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
# 新增内容
server{
listen 8090;
server_name 127.0.0.1;
charset UTF-8;
access_log /var/log/nginx/myweb_access.log;
error_log /var/log/nginx/myweb_error.log;
client_max_body_size 75M;
# 链接uwsgi服务器, uwsgi_pass 的端口与uwsgi设置的socket= :8080 端口一致
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8080;
uwsgi_read_timeout 2;
}
# 设置静态资源路径
location /static/ {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /home/tem/static/;
}
}
# 新增内容
server{
listen 7788;
server_name 127.0.0.1;
charset UTF-8;
access_log /var/log/nginx/test1_access.log;
error_log /var/log/nginx/test1_error.log;
client_max_body_size 75M;
# 链接uwsgi服务器, uwsgi_pass 的端口与uwsgi设置的socket= :8080 端口一致
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:7789;
uwsgi_read_timeout 2;
}
}
# 新增内容
server{
listen 8877;
server_name 127.0.0.1;
charset UTF-8;
access_log /var/log/nginx/test2_access.log;
error_log /var/log/nginx/test2_error.log;
client_max_body_size 75M;
# 链接uwsgi服务器, uwsgi_pass 的端口与uwsgi设置的socket= :8080 端口一致
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8878;
uwsgi_read_timeout 2;
}
}
}
4.结果

这个是忘记配置允许访问的ip,debug能出来表示访问的到

5. 结论
将nginx添加server就可以了
本文介绍了如何在CentOS7系统上为Django应用程序配置多个Nginx服务器块。文章从创建Django项目开始,然后详细讲解了如何修改Nginx配置以支持多站点,并在过程中遇到的问题,例如忘记配置允许访问的IP。通过这个教程,读者可以了解到在生产环境中部署Django应用的必要步骤。
425

被折叠的 条评论
为什么被折叠?



