通过Nginx解决网络隔离实践记录详解

通过Nginx解决网络隔离实践记录详解,第1张

通过Nginx解决网络隔离实践记录详解

详细介绍了根据Nginx处理网络保护实践记录的详细描述,原文中根据示例代码的详细描述非常详细,对大家的学习培训或工作有一定的参考价值。有必要的朋友陪我去了解一下。

要求

最近Node的在线服务要转移,所以新申请了两台在线服务器;

服务器部署后,需要验证服务项目是否一切正常,工作环境和网上自然环境网络受到保护,无法立即浏览;但在线服务器可以根据部署服务器浏览,企业办公网可以浏览部署机;

所以按照在部署机部署代理的方法,工作环境需要部署机,然后需要代理上线服务的方法验证服务项目是否全部正常。

整个网络结构如下图所示:

Nginx安装

下载

下载网页:http://nginx.org/en/download.html挑版本号点击鼠标复制连接详细地址

#下载 [work@40-10-14opt]$wgethttp://nginx.org/download/nginx-1.18.0.tar.gz #文件解压 [work@40-10-14opt]$tar-xvfnginx-1.18.0.tar.gz

安装

#1.默认设置安裝:root管理权限进到缓解压力后的文件目录,实行以下指令安裝 [[email protected]]#./configure&&make&&makeinstall #2.特定文件目录:安裝到特定的/opt/nginx文件目录 [work@40-10-14opt]$mkdir/opt/nginx [[email protected]]$./configure--prefix=/opt/nginx&&make&&maeinstall

如果设置了默认安装,非根管理权限将报告以下错误

mkdir:cannotcreatedirectory`/usr/local/nginx':Permissiondenied make[1]:***[install]Error1 make[1]:Leavingdirectory`/opt/nginx-1.18.0' make:***[install]Error2

默认安装后,查询nginx的安装文件,可以看到安装在/usr/local/nginx文件目录下。

[root@40-10-14opt]#whereisnginx nginx:/usr/local/nginx

1.建议采用特定文件目录方法进行安装。如果转换为root管理权限安装,也需要有root管理权限之后才能更改配置文件
2。或者在root安装之后,也可以将管理权限更改为可以实际 *** 作它的单个用户

加软链

有了软链,可以浏览nginx指令的全局性能,不需要把每一个 *** 作都转换成安装文件。

#加上软链 [root@40-10-14sbin]#ln-s/opt/nginx/sbin/nginx/usr/local/bin/ #查询版本号 [root@40-10-14sbin]#nginx-v nginxversion:nginx/1.18.0

常用命令

  • 启动:nginx
  • 终止:nginx-s停止
  • 重启:nginx-s重新加载
  • 辅助说明:nginx-h
  • 强制终止:

    #查询linux过程id [root@40-10-14~]#ps-ef|grepnginx nobody451981016:12?00:00:00nginx:workerprocess root5126150692017:00pts/000:00:00grepnginx #关掉过程 [root@40-10-14~]#kill45198 #以前的过程已被关掉 [root@40-10-14~]#ps-ef|grepnginx root5127750692017:00pts/000:00:00grepnginx

    配备代理人

    要共享两台设备的需求,只需在nginx安装文件下写nginx/conf/nginx.conf文档即可。

    #usernobody; worker_processes1; #error_loglogs/error.log; #error_loglogs/error.lognotice; #error_loglogs/error.loginfo; #pidlogs/nginx.pid; events{ worker_connections1024; } http{ includemime.types; default_typeapplication/octet-stream; #log_formatmain'$remote_addr-$remote_user[$time_local]"$request"' #'$status$body_bytes_sent"$http_referer"' #'"$http_user_agent""$http_x_forwarded_for"'; #access_loglogs/access.logmain; sendfileon; #tcp_nopushon; #keepalive_timeout0; keepalive_timeout65; #gzipon; #要求必须分享到以下两部设备上,总流量均分;特定IP和端口号 upstreamzpserver{ serverxx.xx.xx.22:10001; serverxx.xx.xx.23:10001; } server{ #nginx服务项目端口号为80 listen80; server_namelocalhost; #charsetkoi8-r; #access_loglogs/host.access.logmain; #/user根途径的要求才分享 location/user{ roothtml; indexindex.htmlindex.htm; proxy_passhttp://zpserver; } #error_page404/404.html; #redirectservererrorpagestothestaticpage/50x.html # error_page500502503504/50x.html; location=/50x.html{ roothtml; } #proxythePHPscriptstoApachelisteningon127.0.0.1:80 # #location~\.php${ #proxy_passhttp://127.0.0.1; #} #passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000 # #location~\.php${ #roothtml; #fastcgi_pass127.0.0.1:9000; #fastcgi_indexindex.php; #fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name; #includefastcgi_params; #} #denyaccessto.htaccessfiles,ifApache'sdocumentroot #concurswithnginx'sone # #location~/\.ht{ #denyall; #} } #anothervirtualhostusingmixofIP-,name-,andport-basedconfiguration # #server{ #listen8000; #listensomename:8080; #server_namesomenamealiasanother.alias; #location/{ #roothtml; #indexindex.htmlindex.htm; #} #} #HTTPSserver # #server{ #listen443ssl; #server_namelocalhost; #ssl_certificatecert.pem; #ssl_certificate_keycert.key; #ssl_session_cacheshared:SSL:1米; #ssl_session_timeout5m; #ssl_ciphersHIGH:!aNULL:!MD5; #ssl_prefer_server_cipherson; #location/{ #roothtml; #indexindex.htmlindex.htm; #} #} }

    注意:更改nginx的环境变量后,必须 *** 作nginx-sreload才能生效

    认证

    因为很多在线服务都是需要登录的,必须使用网站域名才能浏览,而不能使用IP浏览,因为cookie都是用域名解析的。

    处理这个问题很简单,装备设备主机就行了。

    #IP为Nginx服务器IP xx.xx.xx.14xxx.daojia.com

    根据设备,在设备的电脑浏览器上需要xxx.daojia.com根据部署机中的Nginx间接浏览在线服务,因此服务项目是否合适由内网检查;服务项目正常后,切总在线流量。

    至此,这篇关于根据Nginx处理网络保护实践记录的详细描述已经在这里详细介绍过了。有关Nginx网络保护的大量信息,请搜索您以前的文章或再次访问下面的相关文章。期待你以后的申请!

    欢迎分享,转载请注明来源:内存溢出

    原文地址: https://outofmemory.cn/zz/774537.html

    (0)
    打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
    上一篇 2022-05-03
    下一篇 2022-05-03

    发表评论

    登录后才能评论

    评论列表(0条)

    保存