当前位置: 首页 > news >正文

ubuntu22.04离线安装nginx

nginx: download下载地址

cd /data
tar -zxvf nginx-1.27.3.tar.gz
cd nginx-1.27.3
useradd nginx

安装依赖

百度网盘地址如下

通过网盘分享的文件:yilai.zip
链接: https://pan.baidu.com/s/1HNOV-fpBTdskDBl0pR8jug?pwd=1234 提取码: 1234

#安装所有依赖

sudo dpkg -i ./*.deb

 cd /data/nginx-1.27.3

 下面代码直接执行

./configure  \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/do/nginx/tmp/client \
--http-proxy-temp-path=/do/nginx/tmp/nginx/proxy \
--http-fastcgi-temp-path=/do/nginx/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/do/nginx/tmp/nginx/uwsgi \
--http-scgi-temp-path=/do/nginx/tmp/nginx/scgi \
--user=nginx \
--group=nginx \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-threads \
--with-stream \
--with-stream_ssl_module

 

sudo mkdir -p /do/nginx/tmp/client
sudo mkdir -p /do/nginx/tmp/nginx/proxy 
sudo mkdir -p /do/nginx/tmp/nginx/fcgi 
sudo mkdir -p /do/nginx/tmp/nginx/uwsgi 
sudo mkdir -p /do/nginx/tmp/nginx/scgi 

#编译
make && make install
#查看版本
nginx -v

nginx 服务配置文件

 

sudo vi /etc/systemd/system/nginx.service

#内容如下
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target 

 

配置/etc/nginx/nginx.conf文件

 该配置文件是一个直接监听到端口的配置文件,如果只要监听一个端口直接更改server就行,如果需要监听好几个,可以将其替换成另一个配置文件,再将配置文件统一放入一个目录

如下将/etc/nginx/nginx.conf文件整体替换成以下内容,

    include /etc/nginx/conf.d/*.conf;代表监听这个里面的所有配置文件

/etc/nginx/conf.d/这个目录需要自己创建

user  root;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
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;

    keepalive_timeout  65;

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

 在放一个8001.conf文件在/etc/nginx/conf.d/这个目录里

server {
    listen       8001;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    #前端文件
    location / {
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       root /data/web/;
       try_files $uri $uri/ /index.html last;
       index index.html;
    }

  
    #后端
    location /admin-api {
        proxy_pass http://192.168.1.198:48080/admin-api;
        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_intercept_errors on;
        error_page 301 302 307 = @handle_redirects;
    }
   

    location @handle_redirects {
        set $saved_redirect_location '$upstream_http_location';
        proxy_pass $saved_redirect_location;
    }
    location /static {
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Methods 'GET,POST';
        add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
        alias /mount/static;
        try_files $uri $uri/ /index.html last;
        proxy_store_access user:rw group:rw all:rw;
        index index.html;
       expires      7d;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

 

重启

sudo systemctl restart nginx

相关文章:

  • 用promptfoo做大模型安全性测评
  • P8598 [蓝桥杯 2013 省 AB] 错误票据
  • 深入理解ES6核心特性:现代JavaScript开发的基石
  • 用WebSocket改造优化若依在线用户实时监控
  • WLAN无线2.4G/5G频段划分和可用信道
  • 基于微信小程序的电影院订票选座系统的设计与实现,SSM+Vue+毕业论文+开题报告+任务书+指导搭建视频
  • 使用useVModel简化 Vue 组件中 v-model 的实现
  • 如何创建自定义权限的kubeconfig
  • springboot399-中文社区交流平台(源码+数据库+纯前后端分离+部署讲解等)
  • http状态码503之解决方法(Solution to HTTP Status Code 503)
  • 微信小程序通过http通信控制庐山派
  • [RabbitMQ] 常见面试题汇总 | 工作流程 | 消息可靠性 | 消息顺序性 | 幂等性 | 高级特性 | 延迟队列 | 仲裁队列 | 工作模式 | 消息积压 | 推拉模式
  • 实时图像与视频超分辨率:高效子像素卷积网络(ESPCN)解析
  • CLIP论文学习
  • 985本硕,网络安全方向,走算法还是走开发?
  • 【会议预告】人工智能与材料国际学术会议
  • 沃丰科技大模型标杆案例 | 索尼大模型智能营销机器人建设实践
  • 短视频矩阵碰一碰发视频源码技术开发,支持OEM
  • bypy的依赖库版本问题
  • STL —— 洛谷字符串(string库)入门题(蓝桥杯题目训练)(一)
  • 中国至越南河内国际道路运输线路正式开通
  • 七旬男子驾“老头乐”酒驾被查,曾有两次酒驾两次肇事记录
  • 走进“双遗之城”,领略文武风采:沧州何以成文旅新贵
  • 央行等印发《关于金融支持广州南沙深化面向世界的粤港澳全面合作的意见》
  • 广西壮族自治区党委政法委副书记李文博接受审查调查
  • 外交部:愿同拉美国家共同维护多边贸易体制