theboyaply

学,就硬学!

  • Home
  • Archives
  • Java
  • Maven
  • Docker
  • Kubernetes
  • JavaScript
  • ES6
  • Vue
  • 踩坑记录
  • noted

  • 搜索
element ui vue wsimport webservice npm mysql redis node nginx nfs ftp es6 开发工具 vscode 前端 javascript springboot 常见问题 tomcat oracle jenkins maven k8s Linux gitlab docker java

Linux安装nginx

发表于 2022-01-05 | 分类于 踩坑记录 | 0 | 阅读次数 401
  • 安装基础工具包
    • 安装gcc-c++
    • 安装PCRE库
    • 安装zlib库
    • 安装openssl
  • 安装Nginx
  • 启停

安装基础工具包

Nginx与Redis一样,都是C语言开发的,都需要在Linux上使用C语言编译后才能使用,所以得先安装用于编译的C环境。
安装Redis时,只需要安装下面第一项,而Nginx则需要安装4项:

yum install -y gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

要是上面这4条语句不好用,可以参照下面的方法:

安装gcc-c++

yum install -y gcc automake autoconf libtool make
yum install -y gcc gcc-c++

安装PCRE库

http://www.pcre.org/查看最新安装包。

下载编译和安装:

wget https://github.com/PhilipHazel/pcre2/releases/download/pcre2-10.39/pcre2-10.39.tar.gz
tar -zxvf pcre2-10.39.tar.gz
cd pcre2-10.39
./configure
make
make install

安装zlib库

http://zlib.net/查看最新安装包。

下载编译和安装:

wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install

安装openssl

https://www.openssl.org/source/查看最新安装包。

wget https://www.openssl.org/source/openssl-3.0.0.tar.gz
tar -zxvf openssl-3.0.0.tar.gz

安装Nginx

https://nginx.org/download/查看最新安装包。

下载编译和安装,默认安装到目录/usr/local/nginx:

wget https://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure
make
make install

configure时可以指定参数,例如:

./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-file-aio \
--with-http_realip_module \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.44 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.1.1g

修改nginx配置

vim /usr/local/nginx/conf/nginx.conf

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    # 设置request请求大小
    client_max_body_size 20m;

    server {
        listen       80;
        server_name  localhost;
        charset utf-8;

	location / {
        root   /data/app/frontCode/dist;
	    try_files $uri $uri/ /index.html;
        index  index.html index.htm;
    }

	location /stage-api/ {
		proxy_set_header Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header REMOTE-HOST $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        # rewrite ^.+stage-api/?(.*)$ /$1 break;
		proxy_pass http://localhost:8080/;
	}

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

启停

启动:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
停止:/usr/local/nginx/sbin/nginx -s stop
重新载入配置文件:/usr/local/nginx/sbin/nginx -s reload

-- end --

# Linux # nginx
Linux安装nfs
Linux安装node
  • 文章目录
  • 站点概览
theboyaply

theboyaply

好记性不如烂笔头

185 日志
13 分类
27 标签
Github E-mail
Creative Commons
0%
© 2019 — 2023 theboyaply
由 Halo 强力驱动
|
主题 - NexT.Gemini
湘ICP备19009291号

湘公网安备 43312402001034号