nginx + django 两种配置模式

本文详细介绍了HTTP服务器配置中的prefork、threaded方式及反向代理服务器的使用方法,包括配置文件详解及实例应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 prefork方式

server {
    listen 80;
    server_name test.tmdxy.org;
    access_log    /var/log/httpd/access.log main;
    location / {
            # host and port to fastcgi server
            fastcgi_pass unix:/tmp/test_tmdxy.sock;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_param REQUEST_METHOD $request_method;
            fastcgi_param QUERY_STRING $query_string;
            fastcgi_param CONTENT_TYPE $content_type;
            fastcgi_param CONTENT_LENGTH $content_length;
            fastcgi_pass_header Authorization;
            fastcgi_param REMOTE_ADDR           $remote_addr;
            fastcgi_param SERVER_PROTOCOL       $server_protocol;
            fastcgi_param SERVER_PORT           $server_port;
            fastcgi_param SERVER_NAME           $server_name;
            fastcgi_intercept_errors off;
        }
    location ^~ /media/ {
        alias    /home/www/django/test_tmdxy_org/meida/;
    }
    location ~* ^.+\.(gif|png|jpg|jpeg|css|swf|htm|html|asp|php|jsp|js|doc|txt)$ {
        root    /home/www/django/test_tmdxy_org/media/;
        access_log   off;
    }
}
2 threaded方式

server {
    listen 80;
    server_name test.tmdxy.org;
    access_log    /var/log/httpd/access.log main;
    location / {
            # host and port to fastcgi server
            fastcgi_pass 127.0.0.1:3033;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_param REQUEST_METHOD $request_method;
            fastcgi_param QUERY_STRING $query_string;
            fastcgi_param CONTENT_TYPE $content_type;
            fastcgi_param CONTENT_LENGTH $content_length;
            fastcgi_pass_header Authorization;
            fastcgi_param REMOTE_ADDR           $remote_addr;
            fastcgi_param SERVER_PROTOCOL       $server_protocol;
            fastcgi_param SERVER_PORT           $server_port;
            fastcgi_param SERVER_NAME           $server_name;
            fastcgi_intercept_errors off;
        }
    location ^~ /media/ {
        alias    /home/www/django/test_tmdxy_org/meida/;
    }
    location ~* ^.+\.(gif|png|jpg|jpeg|css|swf|htm|html|asp|php|jsp|js|doc|txt)$ {
        root    /home/www/django/test_tmdxy_org/media/;
        access_log   off;
    }
}
3.配置反向代理服务器 
只需在server {}里加入

location /go/ {
    proxy_pass http://192.168.1.5:8088/; 
    proxy_redirect http://192.168.1.5:8088/ /;
}

转载于:https://my.oschina.net/ilyaw/blog/37063

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值