在linux環境下離線安裝Nginx

Nginx安裝需要gcc-c++編譯環境,另外還需要安裝Nginx依賴包。

下載gcc-c++

打開gcc-c++ rpm下載地址:https://pkgs.org/download/gcc-c++

選擇對應的Linux CentOS版本進行下載:

 

最新的選擇CentOS7,爲了保險起見,我們選擇最多的rpm支持版本

 

將這些rpm逐個下載即可。下載時需要進入到每一個頁面對應的Download:

 

注:爲了不出錯,將以上列舉的*.rpm都下載。

安裝gcc-c++

可以只安裝一個rpm:

rpm -ivh gcc-c++-4.4.7-4.el6.x86_64.rpm #名字自行修改

當然也可以將所有下載的rpm文件放入/home/gcc-c++路徑下,安裝一個路徑下所有rpm包:

#rpm -Uvh *.rpm --nodeps --force  #安裝路徑下所有rpm

安裝軟件示例:

# rpm -hvi dejagnu-1.4.2-10.noarch.rpm

警告:dejagnu-1.4.2-10.noarch.rpm: V3 DSA 簽名:NOKEY, key ID db42a60e準備...           ########################################### [100%]

顯示軟件安裝信息

# rpm -qi dejagnu-1.4.2-10.noarch.rpm

卸載軟件示例:

pm –e [your package]

注意:是安裝後的包,可能與原包名稱有差異。

安裝zlib-devel

下載方式同gcc-c++方式,單個rpm安裝:

rpm -ivh zlib-devel-1.2.3-29.el6.x86_64.rpm

注意:系統版本要對應,如依然報錯請安裝openssl openssl-devel

​​​​​​​Nginx上傳解壓編譯

上傳:

可以通過TFP上傳文件到服務器/home路徑下。

解壓:

tar -zxvf nginx-1.17.2.tar.gz

編譯:

進入路徑/home/nginx/nginx-1.17.2,

依次執行如下命令:

./configure  --prefix=/home/nginx/nginx

make

make install

如此即可安裝上Nginx,此時會爲我們生成/home/nginx/nginx

注:可啓動文件在/home/nginx/nginx/sbin下。

​​​​​​​Nginx啓動、重載和停止

啓動:/home/nginx/nginx/sbin/nginx

重載:/home/nginx/nginx/sbin/nginx -s reload

停止:/home/nginx/nginx/sbin/nginx -s stop

注意:/home/nginx/nginx/sbin/nginx -s start啓動不了Nginx。

​​​​​​​Nginx本機代理配置

修改/home/nginx/nginx/conf/nginx.conf,Nginx代理監聽8090端口。

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8090;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        # 代理同步服務服務端
        location ^~ /datasynchronize-server/ {
            proxy_pass  http://10.0.70.106:8090/datasynchronize-server/;
			# 以下配置支持ws服務
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "Upgrade";
        }

        #代理本機同步服務客戶端
        location ^~ /datasynchronize/ {
            proxy_pass  http://10.0.70.103:8080/datasynchronize/;
			# 以下配置支持ws服務
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "Upgrade";
        }

        # 圖片上傳路徑-Nginx代理後臺管理系統訪問圖片
        location ^~ /upload/ {
            alias  /usr/Tomcat/apache-tomcat-8.5.43-8082/webapps/ROOT/upload/;
        }

        location ^~ /server/upload/ {
             proxy_pass  http://localhost:8082/upload/;
        }


        #默認代理本機啄木鳥服務
        location / {
            root   html;
            index  index.html index.htm;
            proxy_pass  http://10.0.70.103:8082;
			# 以下配置支持ws服務
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "Upgrade";
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章