Nginx (engine x) 是一个轻量级、高性能的HTTP和反向代理web服务器,其特点是占有内存少,并发能力强,事实上nginx的并发能力在同类型的网页服务器中表现较好。
1. 实验环境
系统版本:SLE-12-SP5-Server
2. 准备依赖包、安装包
gcc |
gcc-c++ |
pcre-8.32.tar.gz |
nginx-1.24.0.tar.gz |
zlib(可通过zypper安装) |
openssl(可通过zypper安装) |
3. 上传依赖包、安装包
可通过ftp/sftp上传,也可以通过rzsz上传文件
通过rzsz上传先检查系统是否已安装rzsz组件:
suse:/opt # zypper se rzsz
Loading repository data...
Reading installed packages...
S | Name | Summary | Type
---+------+---------------------------------------------+-----------
i+ | rzsz | X-, Y-, and Z-Modem Data Transfer Protocols | package
| rzsz | X-, Y-, and Z-Modem Data Transfer Protocols | srcpackage
上传pcre-8.32.tar.gz、nginx-1.24.0.tar.gz到/opt目录:
4. 安装依赖
通过zypper安装gcc、gcc-c++
通过zypper安装libopenssl-devel
zypper in libopenssl-devel
通过zypper安装zlib-devel
suse:/opt # zypper se zlib
Loading repository data...
Reading installed packages...
S | Name | Summary | Type
--+------------+--------------------------------------------------------+-----------
| zlib | Library implementing the DEFLATE compression algorithm | srcpackage
i | zlib-devel | Development files for zlib, a data compression library | package
解压pcre-8.32.tar.gz
suse:/opt # tar -zxvf pcre-8.32.tar.gz
pcre-8.32/
pcre-8.32/m4/
pcre-8.32/m4/libtool.m4
pcre-8.32/m4/ax_pthread.m4
pcre-8.32/m4/ltversion.m4
pcre-8.32/m4/lt~obsolete.m4
pcre-8.32/m4/ltoptions.m4
pcre-8.32/m4/pcre_visibility.m4
pcre-8.32/m4/ltsugar.m4
pcre-8.32/doc/
pcre-8.32/doc/html/
pcre-8.32/doc/html/pcre16.html
pcre-8.32/doc/html/pcre_assign_jit_stack.html
pcre-8.32/doc/html/pcre.html
pcre-8.32/doc/html/pcreperform.html
pcre-8.32/doc/html/pcrepartial.html
pcre-8.32/doc/html/pcreunicode.html
pcre-8.32/doc/html/pcre_study.html
pcre-8.32/doc/html/pcre_free_study.html
pcre-8.32/doc/html/pcre_get_named_substring.html
pcre-8.32/doc/html/pcreapi.html
pcre-8.32/doc/html/pcre_copy_substring.html
pcre-8.32/doc/html/pcre_maketables.html
pcre-8.32/doc/html/pcrecompat.html
pcre-8.32/doc/html/pcre_jit_stack_alloc.html
pcre-8.32/doc/html/pcre_compile2.html
pcre-8.32/doc/html/index.html
pcre-8.32/doc/html/pcre_pattern_to_host_byte_order.html
pcre-8.32/doc/html/pcre_get_stringnumber.html
pcre-8.32/doc/html/pcre_utf16_to_host_byte_order.html
pcre-8.32/doc/html/pcre_refcount.html
pcre-8.32/doc/html/pcre_get_stringtable_entries.html
pcre-8.32/doc/html/pcrecpp.html
pcre-8.32/doc/html/pcredemo.html
pcre-8.32/doc/html/pcre_get_substring_list.html
pcre-8.32/doc/html/pcresyntax.html
pcre-8.32/doc/html/pcre_free_substring.html
pcre-8.32/doc/html/pcrestack.html
pcre-8.32/doc/html/pcre_fullinfo.html
pcre-8.32/doc/html/pcrecallout.html
pcre-8.32/doc/html/pcretest.html
pcre-8.32/doc/html/pcreprecompile.html
pcre-8.32/doc/html/pcrejit.html
pcre-8.32/doc/html/pcre_jit_exec.html
pcre-8.32/doc/html/pcre_jit_stack_free.html
pcre-8.32/doc/html/pcrepattern.html
pcre-8.32/doc/html/pcre-config.html
pcre-8.32/doc/html/pcre_config.html
pcre-8.32/doc/html/pcre_version.html
pcre-8.32/doc/html/pcreposix.html
pcre-8.32/doc/html/pcrebuild.html
pcre-8.32/doc/html/pcre_exec.html
pcre-8.32/doc/html/pcrematching.html
pcre-8.32/doc/html/pcre_get_substring.html
pcre-8.32/doc/html/pcresample.html
pcre-8.32/doc/html/pcre_free_substring_list.html
pcre-8.32/doc/html/pcregrep.html
pcre-8.32/doc/html/pcrelimits.html
pcre-8.32/doc/html/pcre_copy_named_substring.html
pcre-8.32/doc/html/pcre_compile.html
pcre-8.32/doc/html/pcre_dfa_exec.html
pcre-8.32/doc/pcre_maketables.3
pcre-8.32/doc/pcre_utf32_to_host_byte_order.3
pcre-8.32/doc/index.html.src
pcre-8.32/doc/pcre_get_substring_list.3
pcre-8.32/doc/pcreposix.3
pcre-8.32/doc/pcrebuild.3
pcre-8.32/doc/pcregrep.txt
pcre-8.32/doc/pcreperform.3
pcre-8.32/doc/pcreapi.3
pcre-8.32/doc/pcrecpp.3
pcre-8.32/doc/pcrejit.3
pcre-8.32/doc/pcre_get_substring.3
pcre-8.32/doc/pcre_free_substring.3
pcre-8.32/doc/pcrepattern.3
pcre-8.32/doc/pcre_pattern_to_host_byte_order.3
pcre-8.32/doc/pcretest.txt
pcre-8.32/doc/pcregrep.1
pcre-8.32/doc/pcre_free_study.3
pcre-8.32/doc/pcre_jit_stack_alloc.3
pcre-8.32/doc/pcre_dfa_exec.3
pcre-8.32/doc/pcre_free_substring_list.3
pcre-8.32/doc/pcre_version.3
pcre-8.32/doc/pcre_utf16_to_host_byte_order.3
pcre-8.32/doc/pcrecompat.3
pcre-8.32/doc/pcretest.1
pcre-8.32/doc/pcre_exec.3
pcre-8.32/doc/pcrecallout.3
pcre-8.32/doc/pcre_copy_substring.3
pcre-8.32/doc/pcresyntax.3
pcre-8.32/doc/pcrestack.3
pcre-8.32/doc/pcre-config.txt
pcre-8.32/doc/pcre_study.3
pcre-8.32/doc/pcrematching.3
pcre-8.32/doc/pcre_get_named_substring.3
pcre-8.32/doc/pcre.3
pcre-8.32/doc/pcre_compile.3
pcre-8.32/doc/pcre16.3
pcre-8.32/doc/pcre32.3
pcre-8.32/doc/pcre.txt
pcre-8.32/doc/perltest.txt
pcre-8.32/doc/pcre_config.3
pcre-8.32/doc/pcre_jit_stack_free.3
pcre-8.32/doc/pcre_get_stringnumber.3
pcre-8.32/doc/pcre_compile2.3
pcre-8.32/doc/pcrelimits.3
pcre-8.32/doc/pcre_get_stringtable_entries.3
pcre-8.32/doc/pcreprecompile.3
pcre-8.32/doc/pcrepartial.3
pcre-8.32/doc/pcre_assign_jit_stack.3
pcre-8.32/doc/pcre_copy_named_substring.3
pcre-8.32/doc/pcre_fullinfo.3
pcre-8.32/doc/pcre_jit_exec.3
pcre-8.32/doc/pcreunicode.3
pcre-8.32/doc/pcresample.3
pcre-8.32/doc/pcre-config.1
pcre-8.32/doc/pcre_refcount.3
pcre-8.32/NEWS
pcre-8.32/pcre_maketables.c
pcre-8.32/pcreposix.c
pcre-8.32/pcreposix.h
pcre-8.32/CheckMan
pcre-8.32/pcre32_dfa_exec.c
pcre-8.32/compile
pcre-8.32/pcre.h.in
pcre-8.32/NON-AUTOTOOLS-BUILD
pcre-8.32/pcre32_byte_order.c
pcre-8.32/depcomp
pcre-8.32/pcre32_tables.c
pcre-8.32/pcre_scanner_unittest.cc
pcre-8.32/pcre_stringpiece.h.in
pcre-8.32/pcre_string_utils.c
pcre-8.32/pcrecpp.h
pcre-8.32/pcre16_printint.c
pcre-8.32/pcre_jit_test.c
pcre-8.32/PrepareRelease
pcre-8.32/LICENCE
pcre-8.32/pcre_get.c
pcre-8.32/cmake/
pcre-8.32/cmake/FindPackageHandleStandardArgs.cmake
pcre-8.32/cmake/FindEditline.cmake
pcre-8.32/cmake/FindReadline.cmake
pcre-8.32/cmake/COPYING-CMAKE-SCRIPTS
pcre-8.32/aclocal.m4
pcre-8.32/pcre_byte_order.c
pcre-8.32/pcre_ucd.c
pcre-8.32/sljit/
pcre-8.32/sljit/sljitUtils.c
pcre-8.32/sljit/sljitNativePPC_32.c
pcre-8.32/sljit/sljitNativePPC_64.c
pcre-8.32/sljit/sljitNativeX86_32.c
pcre-8.32/sljit/sljitNativeX86_64.c
pcre-8.32/sljit/sljitConfig.h
pcre-8.32/sljit/sljitNativeARM_Thumb2.c
pcre-8.32/sljit/sljitNativeSPARC_32.c
pcre-8.32/sljit/sljitNativeARM_v5.c
pcre-8.32/sljit/sljitNativePPC_common.c
pcre-8.32/sljit/sljitExecAllocator.c
pcre-8.32/sljit/sljitConfigInternal.h
pcre-8.32/sljit/sljitNativeMIPS_common.c
pcre-8.32/sljit/sljitNativeX86_common.c
pcre-8.32/sljit/sljitNativeMIPS_32.c
pcre-8.32/sljit/sljitNativeSPARC_common.c
pcre-8.32/sljit/sljitLir.c
pcre-8.32/sljit/sljitLir.h
pcre-8.32/ucp.h
pcre-8.32/perltest.pl
pcre-8.32/pcre32_printint.c
pcre-8.32/README
pcre-8.32/pcrecpp.cc
pcre-8.32/pcredemo.c
pcre-8.32/makevp.bat
pcre-8.32/pcre_globals.c
pcre-8.32/ltmain.sh
pcre-8.32/configure
pcre-8.32/pcregrep.c
pcre-8.32/pcre16_globals.c
pcre-8.32/pcre_dfa_exec.c
pcre-8.32/libpcre16.pc.in
pcre-8.32/CMakeLists.txt
pcre-8.32/pcre_newline.c
pcre-8.32/pcre_valid_utf8.c
pcre-8.32/configure.ac
pcre-8.32/pcre_version.c
pcre-8.32/pcre32_get.c
pcre-8.32/pcre32_ucd.c
pcre-8.32/testdata/
pcre-8.32/testdata/testoutput1
pcre-8.32/testdata/testoutput2
pcre-8.32/testdata/testoutput3
pcre-8.32/testdata/testoutput4
pcre-8.32/testdata/testoutput5
pcre-8.32/testdata/testoutput6
pcre-8.32/testdata/testoutput7
pcre-8.32/testdata/testoutput8
pcre-8.32/testdata/testoutput9
pcre-8.32/testdata/testinput10
pcre-8.32/testdata/testinput11
pcre-8.32/testdata/testinput12
pcre-8.32/testdata/testinput13
pcre-8.32/testdata/testinput14
pcre-8.32/testdata/testinput15
pcre-8.32/testdata/testinput16
pcre-8.32/testdata/testinput17
pcre-8.32/testdata/testinput18
pcre-8.32/testdata/testinput19
pcre-8.32/testdata/testinput20
pcre-8.32/testdata/testinput21
pcre-8.32/testdata/testinput22
pcre-8.32/testdata/testinput23
pcre-8.32/testdata/testinput24
pcre-8.32/testdata/testinput25
pcre-8.32/testdata/testinput26
pcre-8.32/testdata/testoutput11-8
pcre-8.32/testdata/testinput1
pcre-8.32/testdata/testinput2
pcre-8.32/testdata/testinput3
pcre-8.32/testdata/testinput4
pcre-8.32/testdata/testinput5
pcre-8.32/testdata/testinput6
pcre-8.32/testdata/testinput7
pcre-8.32/testdata/testinput8
pcre-8.32/testdata/testinput9
pcre-8.32/testdata/saved16
pcre-8.32/testdata/saved32
pcre-8.32/testdata/greplist
pcre-8.32/testdata/grepinput
pcre-8.32/testdata/testoutput11-16
pcre-8.32/testdata/testoutput11-32
pcre-8.32/testdata/testoutput18-16
pcre-8.32/testdata/testoutput18-32
pcre-8.32/testdata/testoutput21-16
pcre-8.32/testdata/testoutput21-32
pcre-8.32/testdata/testoutput22-16
pcre-8.32/testdata/testoutput22-32
pcre-8.32/testdata/greppatN4
pcre-8.32/testdata/grepbinary
pcre-8.32/testdata/testoutputEBC
pcre-8.32/testdata/testoutput10
pcre-8.32/testdata/testoutput12
pcre-8.32/testdata/testoutput13
pcre-8.32/testdata/testoutput14
pcre-8.32/testdata/testoutput15
pcre-8.32/testdata/testoutput16
pcre-8.32/testdata/testoutput17
pcre-8.32/testdata/testoutput19
pcre-8.32/testdata/testoutput20
pcre-8.32/testdata/testoutput23
pcre-8.32/testdata/testoutput24
pcre-8.32/testdata/testoutput25
pcre-8.32/testdata/testoutput26
pcre-8.32/testdata/grepinput3
pcre-8.32/testdata/grepinput8
pcre-8.32/testdata/grepinputv
pcre-8.32/testdata/grepinputx
pcre-8.32/testdata/saved16BE-1
pcre-8.32/testdata/saved16BE-2
pcre-8.32/testdata/saved16LE-1
pcre-8.32/testdata/saved16LE-2
pcre-8.32/testdata/saved32BE-1
pcre-8.32/testdata/saved32BE-2
pcre-8.32/testdata/saved32LE-1
pcre-8.32/testdata/saved32LE-2
pcre-8.32/testdata/grepoutput
pcre-8.32/testdata/grepoutput8
pcre-8.32/testdata/grepoutputN
pcre-8.32/testdata/wintestoutput3
pcre-8.32/testdata/testinputEBC
pcre-8.32/testdata/saved8
pcre-8.32/testdata/grepfilelist
pcre-8.32/testdata/wintestinput3
pcre-8.32/config.guess
pcre-8.32/pcre32_string_utils.c
pcre-8.32/pcre16_newline.c
pcre-8.32/install-sh
pcre-8.32/pcre16_version.c
pcre-8.32/pcre16_xclass.c
pcre-8.32/pcre_ord2utf8.c
pcre-8.32/Detrail
pcre-8.32/pcretest.c
pcre-8.32/RunGrepTest
pcre-8.32/pcre_exec.c
pcre-8.32/config.sub
pcre-8.32/pcre32_valid_utf32.c
pcre-8.32/pcre_printint.c
pcre-8.32/missing
pcre-8.32/dftables.c
pcre-8.32/pcregexp.pas
pcre-8.32/HACKING
pcre-8.32/pcrecpp_internal.h
pcre-8.32/pcre32_ord2utf32.c
pcre-8.32/pcre16_study.c
pcre-8.32/pcrecpp_unittest.cc
pcre-8.32/pcre_stringpiece.cc
pcre-8.32/pcre_jit_compile.c
pcre-8.32/config.h.generic
pcre-8.32/Makefile.am
pcre-8.32/Makefile.in
pcre-8.32/pcre32_jit_compile.c
pcre-8.32/pcre32_exec.c
pcre-8.32/NON-UNIX-USE
pcre-8.32/pcre16_config.c
pcre-8.32/pcre32_globals.c
pcre-8.32/pcre16_valid_utf16.c
pcre-8.32/pcre_xclass.c
pcre-8.32/RunTest.bat
pcre-8.32/pcre_study.c
pcre-8.32/pcre_internal.h
pcre-8.32/pcre16_maketables.c
pcre-8.32/config.h.in
pcre-8.32/pcre16_tables.c
pcre-8.32/pcre16_chartables.c
pcre-8.32/CleanTxt
pcre-8.32/pcre16_fullinfo.c
pcre-8.32/pcre_compile.c
pcre-8.32/pcre16_jit_compile.c
pcre-8.32/RunTest
pcre-8.32/pcre32_newline.c
pcre-8.32/pcre32_fullinfo.c
pcre-8.32/pcre32_version.c
pcre-8.32/pcrecpparg.h.in
pcre-8.32/makevp_c.txt
pcre-8.32/pcre32_study.c
pcre-8.32/makevp_l.txt
pcre-8.32/pcre16_compile.c
pcre-8.32/pcre16_refcount.c
pcre-8.32/pcre_scanner.cc
pcre-8.32/pcre_config.c
pcre-8.32/pcre16_byte_order.c
pcre-8.32/pcre16_get.c
pcre-8.32/AUTHORS
pcre-8.32/pcre16_ucd.c
pcre-8.32/pcre32_refcount.c
pcre-8.32/pcre_tables.c
pcre-8.32/pcre16_exec.c
pcre-8.32/pcre16_string_utils.c
pcre-8.32/libpcrecpp.pc.in
pcre-8.32/INSTALL
pcre-8.32/libpcre.pc.in
pcre-8.32/pcre.h.generic
pcre-8.32/pcre32_xclass.c
pcre-8.32/config-cmake.h.in
pcre-8.32/pcre_stringpiece_unittest.cc
pcre-8.32/pcre_scanner.h
pcre-8.32/ChangeLog
pcre-8.32/132html
pcre-8.32/pcre16_utf16_utils.c
pcre-8.32/libpcre32.pc.in
pcre-8.32/libpcreposix.pc.in
pcre-8.32/COPYING
pcre-8.32/pcre_fullinfo.c
pcre-8.32/pcre32_maketables.c
pcre-8.32/pcre32_chartables.c
pcre-8.32/pcre-config.in
pcre-8.32/pcre16_ord2utf16.c
pcre-8.32/pcre32_compile.c
pcre-8.32/pcre_chartables.c.dist
pcre-8.32/pcre16_dfa_exec.c
pcre-8.32/pcre32_utf32_utils.c
pcre-8.32/pcre_refcount.c
pcre-8.32/pcre32_config.c
suse:/opt #
5. 解压nginx-1.24.0.tar.gz
tar -zxvf nginx-1.24.0.tar.gz
6. 创建nginx用户和用户组
6.1 创建nginx用户组
groupadd -r nginx
groupadd命令参数:
suse:/opt # groupadd --help
Usage: groupadd [options] GROUP
Options:
-f, --force exit successfully if the group already exists,
and cancel -g if the GID is already used
-g, --gid GID use GID for the new group
-h, --help display this help message and exit
-K, --key KEY=VALUE override /etc/login.defs defaults
-o, --non-unique allow to create groups with duplicate
(non-unique) GID
-p, --password PASSWORD use this encrypted password for the new group
-r, --system create a system account
-R, --root CHROOT_DIR directory to chroot into
suse:~ # groupadd --help
用法:groupadd [选项] 组
选项:
-f, --force 如果组已经存在则成功退出
并且如果 GID 已经存在则取消 -g
-g, --gid GID 为新组使用 GID
-h, --help 显示此帮助信息并推出
-K, --key KEY=VALUE 不使用 /etc/login.defs 中的默认值
-o, --non-unique 允许创建有重复 GID 的组
-p, --password PASSWORD 为新组使用此加密过的密码
-r, --system 创建一个系统账户
-R, --root CHROOT_DIR chroot 到的目录
6.2 创建nginx用户
useradd -r -g nginx -d /usr/local/nginx -M nginx
useradd命令参数:
suse:/opt # useradd --help
Usage: useradd [options] LOGIN
useradd -D
useradd -D [options]
Options:
-b, --base-dir BASE_DIR base directory for the home directory of the
new account
-c, --comment COMMENT GECOS field of the new account
-d, --home-dir HOME_DIR home directory of the new account
-D, --defaults print or change default useradd configuration
-e, --expiredate EXPIRE_DATE expiration date of the new account
-f, --inactive INACTIVE password inactivity period of the new account
-g, --gid GROUP name or ID of the primary group of the new
account
-G, --groups GROUPS list of supplementary groups of the new
account
-h, --help display this help message and exit
-k, --skel SKEL_DIR use this alternative skeleton directory
-K, --key KEY=VALUE override /etc/login.defs defaults
-l, --no-log-init do not add the user to the lastlog and
faillog databases
-m, --create-home create the user's home directory
-M, --no-create-home do not create the user's home directory
-N, --no-user-group do not create a group with the same name as
the user
-o, --non-unique allow to create users with duplicate
(non-unique) UID
-p, --password PASSWORD encrypted password of the new account
-r, --system create a system account
-R, --root CHROOT_DIR directory to chroot into
-s, --shell SHELL login shell of the new account
-u, --uid UID user ID of the new account
-U, --user-group create a group with the same name as the user
-Z, --selinux-user SEUSER use a specific SEUSER for the SELinux user mapping
suse:~ # useradd --help
用法:useradd [选项] 登录
useradd -D
useradd -D [选项]
选项:
-b, --base-dir BASE_DIR 新账户的主目录的基目录
-c, --comment COMMENT 新账户的 GECOS 字段
-d, --home-dir HOME_DIR 新账户的主目录
-D, --defaults 显示或更改默认的 useradd 配置
-e, --expiredate EXPIRE_DATE 新账户的过期日期
-f, --inactive INACTIVE 新账户的密码不活动期
-g, --gid GROUP 新账户主组的名称或 ID
-G, --groups GROUPS 新账户的附加组列表
-h, --help 显示此帮助信息并推出
-k, --skel SKEL_DIR 使用此目录作为骨架目录
-K, --key KEY=VALUE 不使用 /etc/login.defs 中的默认值
-l, --no-log-init 不要将此用户添加到最近登录和登录失败数据库
-m, --create-home 创建用户的主目录
-M, --no-create-home 不创建用户的主目录
-N, --no-user-group 不创建同名的组
-o, --non-unique 允许使用重复的 UID 创建用户
-p, --password PASSWORD 加密后的新账户密码
-r, --system 创建一个系统账户
-R, --root CHROOT_DIR chroot 到的目录
-s, --shell SHELL 新账户的登录 shell
-u, --uid UID 新账户的用户 ID
-U, --user-group 创建与用户同名的组
-Z, --selinux-user SEUSER 为 SELinux 用户映射使用指定 SEUSER
7. 编译安装nginx
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre=/opt/pcre-8.32
suse:/opt/nginx-1.24.0 # ./configure --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-http_ssl_module \
> --with-http_v2_module \
> --with-http_realip_module \
> --with-http_stub_status_module \
> --with-http_gzip_static_module \
> --with-pcre=/opt/pcre-8.32
make && make install
这样安装完成。
查看一下nginx主目录:
suse:/opt/nginx-1.24.0 # cd /usr/local/nginx
suse:/usr/local/nginx # ll
total 16
drwxr-xr-x 2 root root 4096 Dec 13 22:24 conf
drwxr-xr-x 2 root root 4096 Dec 13 22:24 html
drwxr-xr-x 2 root root 4096 Dec 13 22:24 logs
drwxr-xr-x 2 root root 4096 Dec 13 22:24 sbin
PS:由于安全原因,客户要求我们只能用普通用户启动
8. 更改nginx主目录的所有者及组
chown -R nginx:nginx /usr/local/nginx
suse:~ # ls -l /usr/local/nginx
total 16
drwxr-xr-x 2 nginx nginx 4096 Dec 13 22:24 conf
drwxr-xr-x 2 nginx nginx 4096 Dec 13 22:24 html
drwxr-xr-x 2 nginx nginx 4096 Dec 13 22:24 logs
drwxr-xr-x 2 nginx nginx 4096 Dec 13 22:24 sbin
9. 启动nginx
尝试用普通用户启动nginx:
切换到nginx用户:
suse:~ # su - nginx
nginx@suse:~> ll
total 16
drwxr-xr-x 2 nginx nginx 4096 Dec 13 22:24 conf
drwxr-xr-x 2 nginx nginx 4096 Dec 13 22:24 html
drwxr-xr-x 2 nginx nginx 4096 Dec 13 22:24 logs
drwxr-xr-x 2 nginx nginx 4096 Dec 13 22:24 sbin
nginx@suse:~> cd sbin
nginx@suse:~/sbin> ll
total 6736
-rwxr-xr-x 1 nginx nginx 6896776 Dec 13 22:24 nginx
nginx@suse:~/sbin> ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
nginx@suse:~/sbin>
有报错nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
这通常是由于权限问题引起的。
Nginx 默认监听端口 80,而端口号低于 1024 被视为特权端口,只有特定的用户(例如 root 用户)才有权限绑定到这些端口上。因此,当你尝试以非特权用户(例如普通用户)身份启动 Nginx 并绑定到端口 80 时,会出现权限被拒绝的错误。
解决方法:
1.使用特权用户:以 root 用户身份运行 Nginx,这样它将能够绑定到端口 80。但这并不是一个安全的做法,因此只有在必要时才应该这样做。
2.更改端口:将 Nginx 配置文件中的监听端口改为大于 1024 的其他端口,例如 8080。这样,非特权用户就可以启动 Nginx 了。
尝试更改端口:
先备份一份nginx.conf
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
vim /usr/local/nginx/conf/nginx.conf
nginx@suse:~/sbin> cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
nginx@suse:~/sbin> vim /usr/local/nginx/conf/nginx.conf
我把端口从80改成18080:
wq保存退出;
通过/usr/local/nginx/sbin/nginx -t测试一下
nginx@suse:~/sbin> pwd
/usr/local/nginx/sbin
nginx@suse:~/sbin> ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
测试成功,可以正常启动
nginx@suse:~/sbin> ./nginx
nginx@suse:~/sbin> ps -ef|grep nginx
root 13419 1532 0 22:45 pts/0 00:00:00 su - nginx
nginx 13420 13419 0 22:45 pts/0 00:00:00 -bash
nginx 13632 1 0 22:58 ? 00:00:00 nginx: master process ./nginx
nginx 13633 13632 0 22:58 ? 00:00:00 nginx: worker process
nginx 13634 13420 0 22:58 pts/0 00:00:00 ps -ef
nginx 13635 13420 0 22:58 pts/0 00:00:00 grep --color=auto nginx
验证成功