企业网站定制开发nginx安装并配置实现端口转发

1、企业网站定制开发将程序包上传至服务器,企业网站定制开发我这里使用的是nginx-1.21.6.tar.gz
2、解压nginx 

tar -zxvf nginx-1.21.6.tar.gz

3、解压后会在当前目录下生成一个nginx-1.21.6目录
4、进入该目录,执行   --with-stream

./configure --prefix=安装路径 --with-stream     标红部分为必加,不加不支持tcp转发

5、运行命令后可能会出现如下错误,这表示你的服务器上没有pcre 和 pcre-devel和zlib-devel这3       个包,通过yum命令进行安装

  1. ​    yum -y install pcre
  2. ​    yum -y install pcre-devel
  3. ​    yum -y install zlib-devel

6、再次执行第四步中的命令

 7、执行命令进行安装

make && make install

8、到这里nginx已经安装好了,接下来进行nginx.conf文件的配置

        配置文件路径:/你的安装路径/nginx/conf/nginx.conf

 9、编辑配置文件,如下为nginx.conf 默认内容,在修改前请备份该文件

cp nginx.conf nginx_bak.conf
  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. wor{er_connections 1024;
  9. }
  10. }
  11. http {
  12. include mime.types;
  13. default_type application/octet-stream;
  14. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. # '$status $body_bytes_sent "$http_referer" '
  16. # '"$http_user_agent" "$http_x_forwarded_for"';
  17. #access_log logs/access.log main;
  18. sendfile on;
  19. #tcp_nopush on;
  20. "nginx.conf" 117L, 2656C 1,0-1 顶ç«
  21. #keepalive_timeout 0;
  22. keepalive_timeout 65;
  23. #gzip on;
  24. server {
  25. listen 80;
  26. server_name localhost;
  27. #charset koi8-r;
  28. #access_log logs/host.access.log main;
  29. location / {
  30. root html;
  31. index index.html index.htm;
  32. }
  33. #error_page 404 /404.html;
  34. # redirect server error pages to the static page /50x.html
  35. #
  36. error_page 500 502 503 504 /50x.html;
  37. location = /50x.html {
  38. root html;
  39. }
  40. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  41. #
  42. #location ~ \.php$ {
  43. # proxy_pass http://127.0.0.1;
  44. #}
  45. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  46. #
  47. #location ~ \.php$ {
  48. # root html;
  49. # fastcgi_pass 127.0.0.1:9000;
  50. # fastcgi_index index.php;
  51. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  52. # include fastcgi_params;
  53. #}
  54. # deny access to .htaccess files, if Apache's document root
  55. # concurs with nginx's one
  56. #
  57. #location ~ /\.ht {
  58. # deny all;
  59. #}
  60. }
  61. # another virtual host using mix of IP-, name-, and port-based configuration
  62. #
  63. #server {
  64. # listen 8000;
  65. # listen somename:8080;
  66. # server_name somename alias another.alias;
  67. # location / {
  68. # root html;
  69. # index index.html index.htm;
  70. # }
  71. #}
  72. # HTTPS server
  73. #
  74. #server {
  75. # listen 443 ssl;
  76. # server_name localhost;
  77. # ssl_certificate cert.pem;
  78. # ssl_certificate_key cert.key;
  79. # ssl_session_cache shared:SSL:1m;
  80. # ssl_session_timeout 5m;
  81. # ssl_ciphers HIGH:!aNULL:!MD5;
  82. # ssl_prefer_server_ciphers on;
  83. # location / {
  84. # root html;
  85. # index index.html index.htm;
  86. # }
  87. #}
  88. }

10、在配置文件中增加以下内容

  1. stream { --stream部分与http部分平级
  2. #这两段实现的是10.170.12.159:19013端口通过本地服务器的22222端口转发出去
  3. #其中下面的两处mysqltest可以自己起名,但要保证名称相同
  4. upstream mysqltest {
  5. server 10.110.111.159:19013;
  6. }
  7. server {
  8. listen 22222;
  9. proxy_pass mysqltest;
  10. }
  11. }

11、增加内容后的nginx.conf明细内容如下,其中红框部分为本次新增内容,我在这里添加了两个如需转发更多端口在stream中继续增加即可,用于进行(本配置文件内容仅支持端口转发功能)

12、启动nginx

  1. cd /home/collect/nginx/sbin
  2. ./nginx -c /home/collect/nginx/conf/nginx.conf

 

至此端口转发已完成,可以使用了 

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发