Linux安装Nginx及使用

编译安装

  1. Nginx下载地址: http://nginx.org/en/download.html
  2. 编译安装:
    1
    2
    3
    ./configure --with-http_stub_status_module --with-http_ssl_module
    make
    make install

Nginx启动

  1. 启动: /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

  2. nginx.conf配置:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    server {
    listen 8080; //监听的端口
    server_name localhost; //监听的ip地址
    location / { //匹配所有请求
    root /opt/dist; //前端
    }
    location /api {
    proxy_pass http://192.16.18.111:9999; //后端
    rewrite "^/api/(.*)$" /$1 break;
    }
    }
Author: Giftbear
Link: https://giftbear.github.io/2022/09/23/Linux安装Nginx及使用/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.