说明
- 使用的是阿里云服务器
- 服务器配置: Ubuntu22.04 1核1G
- 服务器配置了公网IP: 47.104.92.75
安装 libmaxminddb
在本地下载libmaxminddb
下载地址: github.com/maxmind/lib…
上传libmaxminddb压缩包到服务器
scp libmaxminddb-1.7.1.tar.gz root@47.104.92.75:/root/
在服务器解压libmaxminddb-1.7.1.tar.gz
tar zxvf libmaxminddb-1.7.1.tar.gz
configure
执行 configure 命令
cd libmaxminddb-1.7.1/
./configure
出现以下信息说明configure 成功
root@iZm5e21kfose3jvounwmacZ:~/libmaxminddb-1.7.1# ./configure
checking for pkg-config... no
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking how to print strings... printf
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking whether gcc understands -c and -o together... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... gawk
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... mt
checking if mt is a manifest tool... no
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for sys/param.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /usr/bin/mkdir -p
checking whether make sets $(MAKE)... yes
checking whether make supports the include directive... yes (GNU style)
checking whether make supports nested variables... yes
checking dependency style of gcc... gcc3
checking whether compiler accepts "-fms-extensions"... yes
checking for C/C++ restrict keyword... __restrict__
checking for arpa/inet.h... yes
checking for assert.h... yes
checking for fcntl.h... yes
checking for inttypes.h... (cached) yes
checking for libgen.h... yes
checking for math.h... yes
checking for netdb.h... yes
checking for netinet/in.h... yes
checking for stdarg.h... yes
checking for stdbool.h... yes
checking for stdint.h... (cached) yes
checking for stdio.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking for sys/mman.h... yes
checking for sys/socket.h... yes
checking for sys/stat.h... (cached) yes
checking for sys/time.h... yes
checking for sys/types.h... (cached) yes
checking for unistd.h... (cached) yes
checking for off_t... yes
checking for size_t... yes
checking for ssize_t... yes
checking for uint8_t... yes
checking for uint32_t... yes
checking for uint64_t... yes
checking for unsigned __int128... yes
checking for boolean... no
checking for clock_gettime... yes
checking for open_memstream... yes
checking whether byte ordering is bigendian... no
checking for getpagesize... yes
checking for working mmap... yes
checking for library containing fabs... -lm
checking for library containing fabsf... none required
checking for library containing getaddrinfo... none required
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating src/libmaxminddb.pc
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating bin/Makefile
config.status: creating t/Makefile
config.status: creating config.h
config.status: creating include/maxminddb_config.h
config.status: executing libtool commands
config.status: executing depfiles commands
root@iZm5e21kfose3jvounwmacZ:~/libmaxminddb-1.7.1#
安装 libmaxminddb
执行安装 libmaxminddb 命令
需要在 libmaxminddb-1.7.1 目录下执行
make install
出现以下信息表示 libmaxminddb 安装成功
root@iZm5e21kfose3jvounwmacZ:~/libmaxminddb-1.7.1# make install
Making install in src
make[1]: Entering directory '/root/libmaxminddb-1.7.1/src'
make[2]: Entering directory '/root/libmaxminddb-1.7.1/src'
/usr/bin/mkdir -p '/usr/local/lib'
/bin/bash ../libtool --mode=install /usr/bin/install -c libmaxminddb.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/libmaxminddb.so.0.0.7 /usr/local/lib/libmaxminddb.so.0.0.7
libtool: install: (cd /usr/local/lib && { ln -s -f libmaxminddb.so.0.0.7 libmaxminddb.so.0 || { rm -f libmaxminddb.so.0 && ln -s libmaxminddb.so.0.0.7 libmaxminddb.so.0; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libmaxminddb.so.0.0.7 libmaxminddb.so || { rm -f libmaxminddb.so && ln -s libmaxminddb.so.0.0.7 libmaxminddb.so; }; })
libtool: install: /usr/bin/install -c .libs/libmaxminddb.lai /usr/local/lib/libmaxminddb.la
libtool: install: /usr/bin/install -c .libs/libmaxminddb.a /usr/local/lib/libmaxminddb.a
libtool: install: chmod 644 /usr/local/lib/libmaxminddb.a
libtool: install: ranlib /usr/local/lib/libmaxminddb.a
libtool: finish: PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
/usr/local/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the '-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the 'LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the 'LD_RUN_PATH' environment variable
during linking
- use the '-Wl,-rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to '/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
/usr/bin/mkdir -p '/usr/local/include'
/usr/bin/install -c -m 644 ../include/maxminddb.h '/usr/local/include'
/usr/bin/mkdir -p '/usr/local/lib/pkgconfig'
/usr/bin/install -c -m 644 libmaxminddb.pc '/usr/local/lib/pkgconfig'
make[2]: Leaving directory '/root/libmaxminddb-1.7.1/src'
make[1]: Leaving directory '/root/libmaxminddb-1.7.1/src'
Making install in bin
make[1]: Entering directory '/root/libmaxminddb-1.7.1/bin'
make[2]: Entering directory '/root/libmaxminddb-1.7.1/bin'
/usr/bin/mkdir -p '/usr/local/bin'
/bin/bash ../libtool --mode=install /usr/bin/install -c mmdblookup '/usr/local/bin'
libtool: install: /usr/bin/install -c .libs/mmdblookup /usr/local/bin/mmdblookup
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/root/libmaxminddb-1.7.1/bin'
make[1]: Leaving directory '/root/libmaxminddb-1.7.1/bin'
Making install in t
make[1]: Entering directory '/root/libmaxminddb-1.7.1/t'
cd libtap && make all
make[2]: Entering directory '/root/libmaxminddb-1.7.1/t/libtap'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/root/libmaxminddb-1.7.1/t/libtap'
make[2]: Entering directory '/root/libmaxminddb-1.7.1/t'
make[2]: Nothing to be done for 'install-exec-am'.
make[2]: Nothing to be done for 'install-data-am'.
make[2]: Leaving directory '/root/libmaxminddb-1.7.1/t'
make[1]: Leaving directory '/root/libmaxminddb-1.7.1/t'
make[1]: Entering directory '/root/libmaxminddb-1.7.1'
if [ ! -f man/man1/mmdblookup.1 ]; then mkdir -p man/man1 && touch man/man1/mmdblookup.1; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
make[2]: Entering directory '/root/libmaxminddb-1.7.1'
make[2]: Nothing to be done for 'install-exec-am'.
/usr/bin/mkdir -p '/usr/local/include'
/usr/bin/install -c -m 644 include/maxminddb.h '/usr/local/include'
if [ ! -f man/man1/mmdblookup.1 ]; then mkdir -p man/man1 && touch man/man1/mmdblookup.1; fi
/usr/bin/mkdir -p '/usr/local/share/man/man1'
/usr/bin/install -c -m 644 man/man1/mmdblookup.1 '/usr/local/share/man/man1'
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
if [ ! -f man/man3/libmaxminddb.3 ]; then mkdir -p man/man3 && touch man/man3/libmaxminddb.3; fi
/usr/bin/mkdir -p '/usr/local/share/man/man3'
/usr/bin/install -c -m 644 man/man3/libmaxminddb.3 man/man3/MMDB_aget_value.3 man/man3/MMDB_close.3 man/man3/MMDB_dump_entry_data_list.3 man/man3/MMDB_free_entry_data_list.3 man/man3/MMDB_get_entry_data_list.3 man/man3/MMDB_get_metadata_as_entry_data_list.3 man/man3/MMDB_get_value.3 man/man3/MMDB_lib_version.3 man/man3/MMDB_lookup_sockaddr.3 man/man3/MMDB_lookup_string.3 man/man3/MMDB_open.3 man/man3/MMDB_read_node.3 man/man3/MMDB_strerror.3 man/man3/MMDB_vget_value.3 '/usr/local/share/man/man3'
/usr/bin/mkdir -p '/usr/local/include'
/usr/bin/install -c -m 644 include/maxminddb_config.h '/usr/local/include'
make[2]: Leaving directory '/root/libmaxminddb-1.7.1'
make[1]: Leaving directory '/root/libmaxminddb-1.7.1'
root@iZm5e21kfose3jvounwmacZ:~/libmaxminddb-1.7.1#
安装 nginx, 并安装 geoip2 模块
需要使用源码安装,不能直接使用 apt-get install nginx 这种预编译方式安装
在服务器下载 nginx 源码压缩包
其他 nginx 版本下载连接: nginx.org/download/
wget https://nginx.org/download/nginx-1.23.0.tar.gz
在服务器解压 nginx 源码压缩包
tar zxvf nginx-1.23.0.tar.gz
在本地下载 ngx_http_geoip2_module-3.4.tar.gz
scp ngx_http_geoip2_module-3.4.tar.gz 到服务器
scp ngx_http_geoip2_module-3.4.tar.gz root@47.104.92.75:/root/
在服务器解压 ngx_http_geoip2_module-3.4.tar.gz
tar zxvf ngx_http_geoip2_module-3.4.tar.gz
configure nginx,并添加 geoip2 模块
# cd 到解压后的 nginx 源码目录下
cd nginx-1.23.0
# 执行 configure 命令, --prefix 是 nginx 安装目录,--add-module 是 geoip2 解压后的路径
./configure --prefix=/user/local/nginx --add-module=/root/ngx_http_geoip2_module-3.4
如果 configure 报如下错误,需要安装 libpcre3 libpcre3-dev 依赖
# 报错
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
# 安装依赖
apt-get update
apt-get install libpcre3 libpcre3-dev
以下信息说明 nginx configure 成功
root@iZm5e21kfose3jvounwmacZ:~/nginx-1.23.0# ./configure --prefix=/user/local/nginx --add-module=/root/ngx_http_geoip2_module-3.4
checking for OS
+ Linux 5.15.0-56-generic x86_64
checking for C compiler ... found
+ using GNU C compiler
+ gcc version: 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04)
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for gcc builtin 64 bit byteswap ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
checking for EPOLLEXCLUSIVE ... found
checking for eventfd() ... found
checking for O_PATH ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for prctl(PR_SET_KEEPCAPS) ... found
checking for capabilities ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for UDP_SEGMENT ... found
checking for nobody group ... not found
checking for nogroup group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... found
checking for sched_yield() ... found
checking for sched_setaffinity() ... found
checking for SO_SETFIB ... not found
checking for SO_REUSEPORT ... found
checking for SO_ACCEPTFILTER ... not found
checking for SO_BINDANY ... not found
checking for IP_TRANSPARENT ... found
checking for IP_BINDANY ... not found
checking for IP_BIND_ADDRESS_NO_PORT ... found
checking for IP_RECVDSTADDR ... not found
checking for IP_SENDSRCADDR ... not found
checking for IP_PKTINFO ... found
checking for IPV6_RECVPKTINFO ... found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE ... found
checking for TCP_FASTOPEN ... found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for int size ... 4 bytes
checking for long size ... 8 bytes
checking for long long size ... 8 bytes
checking for void * size ... 8 bytes
checking for uint32_t ... found
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system byte ordering ... little endian
checking for size_t size ... 8 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 8 bytes
checking for AF_INET6 ... found
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for pwritev() ... found
checking for strerrordesc_np() ... found
checking for localtime_r() ... found
checking for clock_gettime(CLOCK_MONOTONIC) ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for POSIX semaphores ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for ioctl(FIONREAD) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for sysconf(_SC_LEVEL1_DCACHE_LINESIZE) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
configuring additional modules
adding module in /root/ngx_http_geoip2_module-3.4
checking for MaxmindDB library ... found
+ ngx_geoip2_module was configured
checking for PCRE2 library ... not found
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for zlib library ... found
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ OpenSSL library is not used
+ using system zlib library
nginx path prefix: "/user/local/nginx"
nginx binary file: "/user/local/nginx/sbin/nginx"
nginx modules path: "/user/local/nginx/modules"
nginx configuration prefix: "/user/local/nginx/conf"
nginx configuration file: "/user/local/nginx/conf/nginx.conf"
nginx pid file: "/user/local/nginx/logs/nginx.pid"
nginx error log file: "/user/local/nginx/logs/error.log"
nginx http access log file: "/user/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
root@iZm5e21kfose3jvounwmacZ:~/nginx-1.23.0#
安装 nginx
需要在 nginx-1.23.0 目录下执行安装命令
make install
以下信息说明 nginx 安装成功
root@iZm5e21kfose3jvounwmacZ:~/nginx-1.23.0# make install
make -f objs/Makefile install
make[1]: Entering directory '/root/nginx-1.23.0'
test -d '/user/local/nginx' || mkdir -p '/user/local/nginx'
test -d '/user/local/nginx/sbin' \
|| mkdir -p '/user/local/nginx/sbin'
test ! -f '/user/local/nginx/sbin/nginx' \
|| mv '/user/local/nginx/sbin/nginx' \
'/user/local/nginx/sbin/nginx.old'
cp objs/nginx '/user/local/nginx/sbin/nginx'
test -d '/user/local/nginx/conf' \
|| mkdir -p '/user/local/nginx/conf'
cp conf/koi-win '/user/local/nginx/conf'
cp conf/koi-utf '/user/local/nginx/conf'
cp conf/win-utf '/user/local/nginx/conf'
test -f '/user/local/nginx/conf/mime.types' \
|| cp conf/mime.types '/user/local/nginx/conf'
cp conf/mime.types '/user/local/nginx/conf/mime.types.default'
test -f '/user/local/nginx/conf/fastcgi_params' \
|| cp conf/fastcgi_params '/user/local/nginx/conf'
cp conf/fastcgi_params \
'/user/local/nginx/conf/fastcgi_params.default'
test -f '/user/local/nginx/conf/fastcgi.conf' \
|| cp conf/fastcgi.conf '/user/local/nginx/conf'
cp conf/fastcgi.conf '/user/local/nginx/conf/fastcgi.conf.default'
test -f '/user/local/nginx/conf/uwsgi_params' \
|| cp conf/uwsgi_params '/user/local/nginx/conf'
cp conf/uwsgi_params \
'/user/local/nginx/conf/uwsgi_params.default'
test -f '/user/local/nginx/conf/scgi_params' \
|| cp conf/scgi_params '/user/local/nginx/conf'
cp conf/scgi_params \
'/user/local/nginx/conf/scgi_params.default'
test -f '/user/local/nginx/conf/nginx.conf' \
|| cp conf/nginx.conf '/user/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/user/local/nginx/conf/nginx.conf.default'
test -d '/user/local/nginx/logs' \
|| mkdir -p '/user/local/nginx/logs'
test -d '/user/local/nginx/logs' \
|| mkdir -p '/user/local/nginx/logs'
test -d '/user/local/nginx/html' \
|| cp -R html '/user/local/nginx'
test -d '/user/local/nginx/logs' \
|| mkdir -p '/user/local/nginx/logs'
make[1]: Leaving directory '/root/nginx-1.23.0'
root@iZm5e21kfose3jvounwmacZ:~/nginx-1.23.0#
查看 nginx 版本
/user/local/nginx/sbin/nginx -v
启动 nginx
/user/local/nginx/sbin/nginx
下载 Geo Lite,并配置 nginx
在本地下载 GeoLite2-Country_20230113.tar.gz
下载地址: dev.maxmind.com/geoip/geoli…
scp GeoLite2-Country_20230113.tar.gz 到服务器
scp GeoLite2-Country_20230113.tar.gz root@47.104.92.75:/root/
解压 GeoLite2-Country_20230113.tar.gz
tar zxvf GeoLite2-Country_20230113.tar.gz
配置 nginx.conf
# 你的 nginx.conf 的位置
vim /user/local/nginx/conf/nginx.conf
# 添加如下配置
http {
# 其他配置
geoip2 /root/GeoLite2-Country_20230113/GeoLite2-Country.mmdb {
$geoip2_country_code country iso_code;
}
server {
location / {
add_header country $geoip2_country_code;
# 其他配置
}
}
}
重启 nginx
# 测试 nginx 配置是否正确
/user/local/nginx/sbin/nginx -t
# 重启 nginx
/user/local/nginx/sbin/nginx -s reload