先去官網下載linux.tar.gz包 http://nginx.org/en/download.html
傳到linxu中
解壓tar包
在軟件包nginx-1.15.9目錄下對NGINX進行配置
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-http_stub_status_module --with-stream
執行以上命令,提示這個信息:說明沒有安裝編譯器
checking for OS
+ Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
解決:yum -install gcc
在執行以上命令提示這個信息
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
解決:yum -y install openssl openssl-devel
配置執行成功:
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx"
nginx configuration file: "/usr/local/nginx/nginx.conf"
nginx pid file: "/usr/local/nginx/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
執行編譯:make
編譯安裝:make install
到NGINX目錄下啓動:./nginx
提示如下信息:
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
緣由:多是進程已經啓動,或者是端口被佔用
解決方式:先查看進程是否啓動:ps -ef |grep nginx。如未啓動,就是緣由二。
緣由二解決方式:到安裝目錄下打開配置文件:vi nginx.conf。將修改成8080,再次啓動便可
啓動成功後瀏覽器中輸入ip和端口訪問。 提示「沒法訪問此網站」 緣由:linux中啓動了防火牆,可經過:systemctl status firewalld命令查看防火牆狀態 解決方式:systemctl stop firewalld 使用該命令禁用防火牆 再次訪問ok