-
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,如下
解決方案:把檢查編譯語句
./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信息。