Nginx配置反向代理uwsgi

uwsgi配置文件路徑:/root/script/uwsgi.ini
nginx根目錄:/etc/nginx
nginx默認配置文件:/etc/nginx/nginx.conf
項目自定義配置文件:/etc/nginx/conf.d/project.confphp

1.uwsgi配置html

# uwsig使用配置文件啓動
[uwsgi]
# 項目目錄
chdir=/root/project
# 指定項目的application
module=project.wsgi:application
# 指定sock的文件路徑
socket=/root/ctguinfowork/script/uwsgi.sock
# 進程個數
workers=5
pidfile=/root/script/uwsgi.pid
# 指定IP端口
http= :8080
# 指定靜態文件,這個項目中沒有,若是你的項目中有靜態文件的話按這個目錄結構配置
static-map=/static=/root/project/static
# 啓動uwsgi的用戶名和用戶組
uid=root
gid=root
# 啓用主進程
master=true
# 自動移除unix Socket和pid文件當服務中止的時候
vacuum=true
# 序列化接受的內容,若是可能的話
thunder-lock=true
# 啓用線程
enable-threads=true
# 設置自中斷時間
harakiri=30
# 設置緩衝
post-buffering=4096
# 設置日誌目錄
daemonize=/root/script/uwsgi.log

2.啓動uwsgi
啓動uwsgi就比較簡單(若是沒有報錯的話):uwsgi --ini /root/script/uwsgi.ini
啓動成功後理論上來講就能夠在瀏覽器欄輸入ip:port來訪問項目了,port爲uwsgi中配置的端口node

3.配置nginx

3.1自定義配置nginx

upstream project{
    server 47.100.118.99:8080;
}

server {
    listen 80;         #監聽端口
    server_name  47.100.118.99;        #訪問地址,這裏比較坑,填什麼就映射什麼,若是你填localhost、127.0.0.1之類的,就意味着你只能在本機瀏覽器上訪問,由於別人在本身電腦輸入127.0.0.1就不是你了

    access_log  /var/log/nginx/project.access.log  main;        #普通日誌
    error_log  /var/log/nginx/project.error.log;            #錯誤日誌
    #root   html;
    #index  index.html index.htm index.php;

    location / {
        proxy_pass  http://project;        #這裏http後等於第一行配置的名字

        #Proxy Settings
        proxy_redirect     off;
        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;
        proxy_max_temp_file_size 0;
        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
   }

3.2 默認配置文件瀏覽器

默認配置文件基本上不用配置,保證其http{}裏面包含上面的自定義文件就行了。app

user root;                #這裏改爲root,由於默認nginx用戶可能沒有權限訪問你的靜態文件
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

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;            #保證配置文件含有咱們的自定義配置,其它路徑也能夠
}
相關文章
相關標籤/搜索