Skip to content

Latest commit

 

History

History
266 lines (232 loc) · 7.25 KB

README.md

File metadata and controls

266 lines (232 loc) · 7.25 KB

部署和编译环境

需要在Linux环境下编译和部署。

相关约束和依赖

  1. Linux环境中需要安装gcc,perl
  2. 尽量使用非root用户进行编译

源代码

  1. nginx-release-1.25.3
  2. openssl-3.2.0
  3. pcre-8.45
  4. zlib-1.3
  5. jansson-2.14
  6. libjwt-1.17.0

安装依赖包

安装openssl

  1. 将openssl-3.2.0.tar.gz进行解压
  2. 执行如下命令
./Configure
  1. 编译
make
  1. 安装(非root用户)
sudo make install
  1. 默认的安装路径为: /usr/local

安装jansson

  1. 将jansson进行解压
  2. 执行如下命令
./configure
  1. 编译
make
  1. 安装(非root用户)
sudo make install
  1. 默认的安装路径为: /usr/local

安装libjwt

  1. 将libjwt进行解压
  2. 执行如下命令
./configure
  1. 编译
make
  1. 安装(非root用户)
sudo make install
  1. 默认的安装路径为: /usr/local

配置当前用户的profile

  1. 打开当前用户的.bash_profile,写入如下配置项
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$/usr/local/lib/pkgconfig

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
  1. 配置完成后,为了使其生效,可以在已经打开的terminal中执行
source ~/.bash_profile

编译nginx

  1. 将nginx源码包进行解压
tar xvzf nginx-release-1.25.3.tar.gz
  1. 在nginx目录中创建objs/lib
mkdir -p objs/lib
  1. 将openssl,pcre,zlib都解压到objs/lib中
  2. 创建html, logs, temp目录
  3. 将工程里的html目录下的文件拷贝到新建的html目录下
  4. 在nginx目录下执行如下命令:
./auto/configure \
    --with-cc=gcc \
    --with-debug \
	--builddir=build \
    --prefix= \
    --conf-path=conf/nginx.conf \
    --pid-path=logs/nginx.pid \
    --http-log-path=logs/access.log \
    --error-log-path=logs/error.log \
    --sbin-path=nginx \
    --http-client-body-temp-path=temp/client_body_temp \
    --http-proxy-temp-path=temp/proxy_temp \
    --http-fastcgi-temp-path=temp/fastcgi_temp \
    --http-scgi-temp-path=temp/scgi_temp \
    --http-uwsgi-temp-path=temp/uwsgi_temp \
    --with-cc-opt=-DFD_SETSIZE=1024 \
    --with-pcre=objs/lib/pcre-8.45 \
    --with-zlib=objs/lib/zlib-1.3 \
	--with-openssl=objs/lib/openssl-3.2.0 \
    --with-openssl-opt=no-asm \
    --with-http_ssl_module \
	--with-http_auth_request_module

此时编译,只能在当前目录下运行nginx

  1. 执行如下命令进行编译:
make -j 10
  1. 运行,然后通过浏览器访问nginx,以检查nginx是否可以正常运行
./build/nginx
  1. 停止
./build/nginx -s stop

带ngx_http_study_module编译

  1. 在nginx目录下创建modules目录
  2. 将ngx_http_sutdy_module拷贝到module目录下
  3. 执行configure命令:
./auto/configure \
    --with-cc=gcc \
    --with-debug \
	--builddir=build \
    --prefix= \
    --conf-path=conf/nginx.conf \
    --pid-path=logs/nginx.pid \
    --http-log-path=logs/access.log \
    --error-log-path=logs/error.log \
    --sbin-path=nginx \
    --http-client-body-temp-path=temp/client_body_temp \
    --http-proxy-temp-path=temp/proxy_temp \
    --http-fastcgi-temp-path=temp/fastcgi_temp \
    --http-scgi-temp-path=temp/scgi_temp \
    --http-uwsgi-temp-path=temp/uwsgi_temp \
    --with-cc-opt=-DFD_SETSIZE=1024 \
    --with-pcre=objs/lib/pcre-8.45 \
    --with-zlib=objs/lib/zlib-1.3 \
	--with-openssl=objs/lib/openssl-3.2.0 \
    --with-openssl-opt=no-asm \
    --with-http_ssl_module \
	--with-http_auth_request_module \
	--add-module=modules/ngx_http_study_module
  1. 编译
make

修改nginx配置文件

可以参考example_config/example_nginx_config.conf进行修改。该文件中将将日志文件按照日期进行拆分.

  1. 打开nginx.conf文件继续编辑
  2. 如果是debug版本,则通过如下配置来打开调试日志进行调试(第8行)
error_log  logs/error.log  debug;
  1. 配置日志输出格式,该日志将会以json格式输出到相关日志文件中。(第26-47行)
log_format main     escape=json '{'
                                          '"timestamp": "$time_local", '
                                         '"remote_addr": "$remote_addr", '
                                         '"remote_user": "$remote_user", '
                                         '"study_username": "$study_username", '
                                         '"study_service_uri": "$study_service_uri", '
                                         '"request_method": "$request_method", '
                                         '"request_uri": "$request_uri", '
                                         '"request_protocol": "$server_protocol", '
                                         '"request_length": "$request_length", '
                                         '"request_time": "$request_time", '
                                         '"response_status": "$status", '
                                         '"body_bytes_sent": "$body_bytes_sent", '
                                         '"bytes_sent": "$bytes_sent", '
                                         '"http_referer": "$http_referer", '
                                         '"http_user_agent": "$http_user_agent", '
                                         '"http_x_forwarded_for": "$http_x_forwarded_for", '
                                         '"http_host": "$http_host", '
                                         '"server_name": "$server_name", '
                                         '"upstream_addr": "$upstream_addr", '
                                         '"upstream_status": "$upstream_status"'
                                         '}';
  1. 修改nginx的access日志格式
access_log  logs/access.log  main;
  1. 修改监听地址和端口
        listen       8081;
        server_name  192.168.56.106;
  1. 配置地图服务代理
    location /xxx/ {
            access_log  logs/xxx_access.log  main;

            study_root xxx;
            study_rex_str ^/geo/(.*)/(MapServer|FeatureServer|ImageServer|SeceneServer);
            study_jwt_key <your security key>

            rewrite ^/gis/(.*)$ /$1 break;

            proxy_set_header Authorization "";

            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_pass https://map.geoq.cn/;
        }

安装

执行如下命令安装nginx

sudo make install
  • nginx的可执行文件被安装到/usr/local/bin
  • nginx的日志和配置文件目录会被安装到/usr/local/nginx目录下

使用systemctl启动nginx服务

  1. 使用管理员将nginx.servce拷贝到/etc/systemd/system目录下
  2. 修改文件权限
chmod +x nginx.service
  1. 启动
systemctl daemon-reload
systemctl enable nginx.service
systemctl start nginx.service
  1. 重新加载和停止
systemctl restart nginx.service
systemctl stop nginx.service