Loading... ## 问题 1. 在服务器A上编译 nginx,移动到服务器B上运行时,提示 **`Illegal instruction (core dumped)`** 2. 制作的 nginx docker 镜像,容器无法在部分服务器上启动,提示 **`Illegal instruction (core dumped)`** ## 网上的解决方案 找到一篇文章,提到了在使用 k8s 运行 nginx 时,主机变化导致的运行异常: https://blog.csdn.net/qq_27565769/article/details/128613121 通过 `cat /proc/couinfo` 查看两台服务器处理器支持的指令集,发现服务器B的确是不支持 SSE4.2,而编译 nginx 的服务器A是支持的   移动到支持 SSE4.2 的服务器上,或在 [编译 Nginx](https://blog.qwerto.cc/install-nginx) 时不使用 SSE4.2 优化 修改编译命令,加入 `--with-cc-opt='-mno-sse4.2'` 参数不使用 SSE4.2 优化: ```bash ./configure --user=www --group=www --prefix=/usr/local/nginx --with-openssl=../openssl-1.1.1w --with-openssl-opt='zlib -march=native -ljemalloc -Wl,-flto -mno-sse4.2' --with-http_ssl_module --with-http_v2_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-zlib=../zlib-cf --with-pcre=../pcre-8.45 --with-pcre-jit --add-module=../ngx_brotli --add-module=../nginx-ct --add-module=../headers-more-nginx-module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v3_module --add-module=../ngx_http_geoip2_module --with-ld-opt='-Wl,-z,relro -Wl,-z,now -fPIC -ljemalloc -lrt' --with-cc-opt='-mno-sse4.2' ``` ## 最终解决方案 参考资料:https://stackoverflow.com/questions/10559275/how-is-march-different-from-mtune 修改编译命令,加入`--with-cc-opt='-mtune=generic'`参数 ```bash ./configure --user=www --group=www --prefix=/usr/local/nginx --with-openssl=../openssl-1.1.1w --with-openssl-opt='zlib -mtune=generic -ljemalloc -Wl,-flto' --with-http_ssl_module --with-http_v2_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-zlib=../zlib-cf --with-pcre=../pcre-8.45 --with-pcre-jit --add-module=../ngx_brotli --add-module=../nginx-ct --add-module=../headers-more-nginx-module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v3_module --add-module=../ngx_http_geoip2_module --with-ld-opt='-Wl,-z,relro -Wl,-z,now -fPIC -ljemalloc -lrt' --with-cc-opt='-mtune=generic' ``` 最后修改:2024 年 07 月 30 日 © 允许规范转载 赞 如果觉得我的文章对你有用,请随意赞赏