Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器


官网: https://nginx.org/en/

nginx ("engine x") is an HTTP web server, reverse proxy, content cache, load balancer, TCP/UDP proxy server, and mail proxy server.

现在开始学习 nginx !粗略学习 nginx 的常用操作,配套案例即可,系统为 CentOS7.9。


nginx 代理 http 转发

可以配置nginx.conf文件,或者在conf.d目录下加 .conf文件。

当你访问 8088 端口可以实现向 11434 端口转发,也就是看到的是 11434 端口提供的内容。

$ cat /etc/nginx/conf.d/ollama.conf 
server {
    listen 8088;
    listen [::]:8088; #1.用户访问这个端口
    server_name j2.biomooc.com;  #1.域名或者IP地址;

    access_log  /var/log/nginx/deepseek_access.log;
    error_log  /var/log/nginx/deepseek_error.log;

    location / {
        proxy_pass http://127.0.0.1:11434/; #2.直接转发给这个服务
        #proxy_buffering off;
        #proxy_http_version 1.1;
        #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        #proxy_set_header Upgrade $http_upgrade;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Connection $http_connection;
    }
}

重启服务
##sudo systemctl restart nginx
$ sudo service nginx restart

参考资料

https://nginx.org/en/