操作nginx时遇到的各种问题
  IGa5K6mVCKZS 2023年11月02日 122 0

1、 command not found

命令找不到

# 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

2、 ./config: No such file or directory

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"

 

 

3、leaving directory /opt/nginx-1.19.0 [build] Error 2

make时出现的错误2,如下

操作nginx时遇到的各种问题_nginx

 

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

./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

 

 

4、/nginx.pid" failed (2: No such file or directory)

解决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

 

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

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

 

6、https改造后,ie和谷歌都能正常使用,但是局方电脑ie访问弹出新窗口后session失效需要重新登录系统

解决方案

原本以为是nginx的配置问题,最后重置ie浏览器后发现正常了

 

7、安装Nginx过程中,使用make时出现 make: *** 没有规则可以创建“default”需要的目标“build”

解决方法:

安装以下依赖包
yum install pcre-devel
yum install zlib zlib-devel
yum install openssl openssl-devel

//也可用一条命令代替
yum install pcre-devel zlib zlib-devel openssl openssl-devel

 

8、nginx默认附件上传为1M 可修改配置文件加大

添加client_max_body_size 1024m; 这行代码即可

比如:

location ^~ /oms/ {
client_max_body_size 1024m;
proxy_pass http://siteHttps/oms/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

 

9、nginx 会话保持的问题,最好设置ip_hash轮询

upstream siteHttps { 
ip_hash;
server 192.168.113.16:5148 ;
server 192.168.113.21:5148 ;
}

 使用nginx负载均衡 登录后不能跳转的问题,也可通过设置ip_hash依据ip分配方式解决。另外一个方法就是修改代码使用redis等中间件管理session,也可以解决此问题。

 

10.关于端口

因为nginx占用一个端口,所有原应用服务的端口需要修改成其他,而nginx的端口就是配置原应用服务的端口。

 

11.https改造完成后,html或者jsp页面中的http超链接 就不能访问了

解决方案
方法一:升级https,链接地址改为https(同时站点也需支持https)
方法二:https页面添加meta元数据 <meta content="referrer" name="unsafe-url">,这样强制添加referer信息

备注:方法二中meta元数据中的name值,还可为:
no-referrer:即不添加referer信息;
origin:即referer信息只有schema://domain:port,即协议://域名:端口,没有路径信息;
no-referrer-when-downgrade:当协议降级时,不发送referer信息,也就是本文描述的问题,
现大多数浏览器默认的;
origin-when-crossorigin:当跨域时,origin类型的referer,即只有协议://域名:端口,没有路径信息;
unsafe-url:始终发送referer信息。

 

 

配置文件,学习连接

​https://baijiahao.baidu.com/s?id=1729793004418584302&wfr=spider&for=pc​

​https://wenku.baidu.com/view/578a545e32b765ce0508763231126edb6f1a7693.html​

菜鸟教程

​https://www.runoob.com/w3cnote/nginx-setup-intro.html​

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
IGa5K6mVCKZS