操作nginx时遇到的各种问题

111111111111111111111111111111111111111111111

命令找不到

# nginx -s reload

-bash: nginx: command not found

原因是没添加环境变量


步骤如下:
1、编辑/etc/profile

vim /etc/profile
2、在最后一行添加配置,:wq保存

PATH=$PATH:/usr/local/nginx/sbin
export PATH
3、使配置立即生效

source /etc/profile

222222222222222222222222222222222

make时出现的错误1,如下

[root@localhost nginx-1.19.1]# make
make -f objs/Makefile
make[1]: Entering directory `/opt/nginx-1.19.1'
cd /usr/local/ssl
&& if [ -f Makefile ]; then make clean; fi
&& ./config --prefix=/usr/local/ssl/.openssl no-shared no-threads
&& make
&& make install_sw LIBDIR=lib
/bin/sh: line 2: ./config: No such file or directory
make[1]: *** [/usr/local/ssl/.openssl/include/openssl/ssl.h] Error 127
make[1]: Leaving directory `/opt/nginx-1.19.1'
make: *** [build] Error 2

解决方案

找到/opt/nginx/nginx-1.19.1/auto/lib/openssl/conf 中

CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
CORE_DEPS="$CORE_DEPS $OPENSSL//.openssl/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
CORE_LIBS="$CORE_LIBS $NGX_LIBPTHREAD"

改为 (去掉多余/.openssl)
CORE_INCS="$CORE_INCS $OPENSSL/include"
CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
CORE_LIBS="$CORE_LIBS $NGX_LIBPTHREAD"

333333333333333333333333333333333333333333333

make时出现的错误2,如下

解决方案:把检查编译语句

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/opt/soft/openssl-1.1.1g

改为

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-debug --with-http_realip_module

444444444444444444444444444444444444444444444444

解决Nginx: [error] open() "/usr/local/Nginx/logs/Nginx.pid

重装nginx出现,重启出现错误

./nginx -s reload

nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

解决办法:

 /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  命令解释:

 -c filename : set configuration file (default: conf/nginx.conf) 设置配置文件

设置成功之后在之前报错的路径下会生成 nginx.pid 文件

  在设置的时候可能会出现如下错误:

nginx: [emerg] bind() to 0.0.0.0:9929 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  这是因为我是重装nginx的,之前nginx没有停掉,可以使用命令杀死nginx进程

ps -ef | grep nginx | grep -v grep | awk '{print $2}' | xargs kill -9
  此时再-c 设置一下配置文件,之后再重启nginx

55555555555555555555555555555555555555555555555

https改造后,javaweb内部的重定向地址还是http的所以报错

解决方案
proxy_pass http://localhost:8080;
proxy_set_header Host $host:$server_port;
proxy_redirect http:// https://;

原文地址:https://www.cnblogs.com/rdchen/p/13408955.html