CentOS 7 安装 Nginx 反向代理 node

安装 nginx

配置 nginx

sudo vim /etc/nginx/nginx.conf, 改成下面配置:

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /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;
    keepalive_timeout   65;

    include /etc/nginx/conf.d/*.conf;
}

在/etc/nginx/conf.d下面新建自己 node server 的配置文件,我的 node server 监听 3000 端口,想用 xxx.yyy.com 域名来访问。
sudo vim /etc/nginx/conf.d/www.yyy.com.conf, 写入如下内容:

server {
        listen 80;
        server_name node.appnongye.com;
        location / {
                proxy_pass http://127.0.0.1:3000/;
                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;
               #client_max_body_size 100m;
        }
}

nginx 配置语法检查

sudo nginx -t

nginx 重启

sudo systemctl restart nginx

你可能感兴趣的:(CentOS 7 安装 Nginx 反向代理 node)