Linux yum 安装nginx

水深无声 2022-07-14 09:22 367阅读 0赞

1、安装

直接运行: yum install nginx

  1. [root@hzw-2312 ~]# yum install nginx
  2. Loaded plugins: fastestmirror, presto
  3. Setting up Install Process
  4. Loading mirror speeds from cached hostfile
  5. * base: mirrors.aliyun.com
  6. * extras: mirrors.aliyun.com
  7. * updates: mirrors.aliyun.com
  8. Resolving Dependencies
  9. --> Running transaction check
  10. ---> Package nginx.x86_64 0:1.10.2-1.el6 will be installed
  11. --> Processing Dependency: nginx-filesystem = 1.10.2-1.el6 for package: nginx-1.10.2-1.el6.x86_64
  12. --> Processing Dependency: nginx-all-modules = 1.10.2-1.el6 for package: nginx-1.10.2-1.el6.x86_64
  13. --> Processing Dependency: nginx-filesystem for package: nginx-1.10.2-1.el6.x86_64
  14. --> Running transaction check
  15. ---> Package nginx-all-modules.noarch 0:1.10.2-1.el6 will be installed
  16. --> Processing Dependency: nginx-mod-stream = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
  17. --> Processing Dependency: nginx-mod-mail = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
  18. --> Processing Dependency: nginx-mod-http-xslt-filter = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
  19. --> Processing Dependency: nginx-mod-http-perl = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
  20. --> Processing Dependency: nginx-mod-http-image-filter = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
  21. --> Processing Dependency: nginx-mod-http-geoip = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
  22. ---> Package nginx-filesystem.noarch 0:1.10.2-1.el6 will be installed
  23. --> Running transaction check
  24. ---> Package nginx-mod-http-geoip.x86_64 0:1.10.2-1.el6 will be installed
  25. --> Processing Dependency: GeoIP for package: nginx-mod-http-geoip-1.10.2-1.el6.x86_64
  26. --> Processing Dependency: libGeoIP.so.1()(64bit) for package: nginx-mod-http-geoip-1.10.2-1.el6.x86_64
  27. ---> Package nginx-mod-http-image-filter.x86_64 0:1.10.2-1.el6 will be installed
  28. --> Processing Dependency: gd for package: nginx-mod-http-image-filter-1.10.2-1.el6.x86_64
  29. --> Processing Dependency: libgd.so.2()(64bit) for package: nginx-mod-http-image-filter-1.10.2-1.el6.x86_64
  30. ---> Package nginx-mod-http-perl.x86_64 0:1.10.2-1.el6 will be installed
  31. ---> Package nginx-mod-http-xslt-filter.x86_64 0:1.10.2-1.el6 will be installed
  32. --> Processing Dependency: libxslt.so.1(LIBXML2_1.0.18)(64bit) for package: nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64
  33. --> Processing Dependency: libxslt.so.1(LIBXML2_1.0.11)(64bit) for package: nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64
  34. --> Processing Dependency: libxslt.so.1()(64bit) for package: nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64
  35. --> Processing Dependency: libexslt.so.0()(64bit) for package: nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64
  36. ---> Package nginx-mod-mail.x86_64 0:1.10.2-1.el6 will be installed
  37. ---> Package nginx-mod-stream.x86_64 0:1.10.2-1.el6 will be installed
  38. --> Running transaction check
  39. ---> Package GeoIP.x86_64 0:1.6.5-1.el6 will be installed
  40. --> Processing Dependency: geoipupdate for package: GeoIP-1.6.5-1.el6.x86_64
  41. --> Processing Dependency: GeoIP-data for package: GeoIP-1.6.5-1.el6.x86_64
  42. ---> Package gd.x86_64 0:2.0.35-11.el6 will be installed
  43. --> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-11.el6.x86_64
  44. ---> Package libxslt.x86_64 0:1.1.26-2.el6_3.1 will be installed
  45. --> Running transaction check
  46. ---> Package GeoIP-GeoLite-data.noarch 0:2016.07-1.el6 will be installed
  47. --> Processing Dependency: GeoIP-GeoLite-data-extra = 2016.07-1.el6 for package: GeoIP-GeoLite-data-2016.07-1.el6.noarch
  48. ---> Package geoipupdate.x86_64 0:2.2.1-2.el6 will be installed
  49. ---> Package libXpm.x86_64 0:3.5.10-2.el6 will be installed
  50. --> Running transaction check
  51. ---> Package GeoIP-GeoLite-data-extra.noarch 0:2016.07-1.el6 will be installed
  52. --> Finished Dependency Resolution
  53. Dependencies Resolved
  54. ==============================================================================================================================================================================================================================================================================
  55. Package Arch Version Repository Size
  56. ==============================================================================================================================================================================================================================================================================
  57. Installing:
  58. nginx x86_64 1.10.2-1.el6 epel 462 k
  59. Installing for dependencies:
  60. GeoIP x86_64 1.6.5-1.el6 epel 113 k
  61. GeoIP-GeoLite-data noarch 2016.07-1.el6 epel 399 k
  62. GeoIP-GeoLite-data-extra noarch 2016.07-1.el6 epel 25 M
  63. gd x86_64 2.0.35-11.el6 base 142 k
  64. geoipupdate x86_64 2.2.1-2.el6 epel 28 k
  65. libXpm x86_64 3.5.10-2.el6 base 51 k
  66. libxslt x86_64 1.1.26-2.el6_3.1 base 452 k
  67. nginx-all-modules noarch 1.10.2-1.el6 epel 7.7 k
  68. nginx-filesystem noarch 1.10.2-1.el6 epel 8.5 k
  69. nginx-mod-http-geoip x86_64 1.10.2-1.el6 epel 14 k
  70. nginx-mod-http-image-filter x86_64 1.10.2-1.el6 epel 16 k
  71. nginx-mod-http-perl x86_64 1.10.2-1.el6 epel 26 k
  72. nginx-mod-http-xslt-filter x86_64 1.10.2-1.el6 epel 16 k
  73. nginx-mod-mail x86_64 1.10.2-1.el6 epel 43 k
  74. nginx-mod-stream x86_64 1.10.2-1.el6 epel 36 k
  75. Transaction Summary
  76. ==============================================================================================================================================================================================================================================================================
  77. Install 16 Package(s)
  78. Total download size: 27 M
  79. Installed size: 58 M
  80. Is this ok [y/N]: y
  81. Downloading Packages:
  82. Setting up and reading Presto delta metadata
  83. Processing delta metadata
  84. Package(s) data still to download: 27 M
  85. (1/16): GeoIP-1.6.5-1.el6.x86_64.rpm | 113 kB 00:00
  86. (2/16): GeoIP-GeoLite-data-2016.07-1.el6.noarch.rpm | 399 kB 00:00
  87. (3/16): GeoIP-GeoLite-data-extra-2016.07-1.el6.noarch.rpm | 25 MB 00:02
  88. (4/16): gd-2.0.35-11.el6.x86_64.rpm | 142 kB 00:00
  89. (5/16): geoipupdate-2.2.1-2.el6.x86_64.rpm | 28 kB 00:00
  90. (6/16): libXpm-3.5.10-2.el6.x86_64.rpm | 51 kB 00:00
  91. (7/16): libxslt-1.1.26-2.el6_3.1.x86_64.rpm | 452 kB 00:00
  92. (8/16): nginx-1.10.2-1.el6.x86_64.rpm | 462 kB 00:00
  93. (9/16): nginx-all-modules-1.10.2-1.el6.noarch.rpm | 7.7 kB 00:00
  94. (10/16): nginx-filesystem-1.10.2-1.el6.noarch.rpm | 8.5 kB 00:00
  95. (11/16): nginx-mod-http-geoip-1.10.2-1.el6.x86_64.rpm | 14 kB 00:00
  96. (12/16): nginx-mod-http-image-filter-1.10.2-1.el6.x86_64.rpm | 16 kB 00:00
  97. (13/16): nginx-mod-http-perl-1.10.2-1.el6.x86_64.rpm | 26 kB 00:00
  98. (14/16): nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64.rpm | 16 kB 00:00
  99. (15/16): nginx-mod-mail-1.10.2-1.el6.x86_64.rpm | 43 kB 00:00
  100. (16/16): nginx-mod-stream-1.10.2-1.el6.x86_64.rpm | 36 kB 00:00
  101. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  102. Total 960 kB/s | 27 MB 00:28
  103. Running rpm_check_debug
  104. Running Transaction Test
  105. Transaction Test Succeeded
  106. Running Transaction
  107. Installing : GeoIP-GeoLite-data-2016.07-1.el6.noarch 1/16
  108. Installing : GeoIP-GeoLite-data-extra-2016.07-1.el6.noarch 2/16
  109. Installing : nginx-filesystem-1.10.2-1.el6.noarch 3/16
  110. Installing : libxslt-1.1.26-2.el6_3.1.x86_64 4/16
  111. Installing : geoipupdate-2.2.1-2.el6.x86_64 5/16
  112. Installing : GeoIP-1.6.5-1.el6.x86_64 6/16
  113. Installing : libXpm-3.5.10-2.el6.x86_64 7/16
  114. Installing : gd-2.0.35-11.el6.x86_64 8/16
  115. Installing : nginx-mod-mail-1.10.2-1.el6.x86_64 9/16
  116. Installing : nginx-mod-stream-1.10.2-1.el6.x86_64 10/16
  117. Installing : nginx-mod-http-perl-1.10.2-1.el6.x86_64 11/16
  118. Installing : nginx-mod-http-image-filter-1.10.2-1.el6.x86_64 12/16
  119. Installing : nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64 13/16
  120. Installing : nginx-1.10.2-1.el6.x86_64 14/16
  121. Installing : nginx-mod-http-geoip-1.10.2-1.el6.x86_64 15/16
  122. Installing : nginx-all-modules-1.10.2-1.el6.noarch 16/16
  123. Verifying : GeoIP-GeoLite-data-extra-2016.07-1.el6.noarch 1/16
  124. Verifying : GeoIP-GeoLite-data-2016.07-1.el6.noarch 2/16
  125. Verifying : nginx-mod-mail-1.10.2-1.el6.x86_64 3/16
  126. Verifying : GeoIP-1.6.5-1.el6.x86_64 4/16
  127. Verifying : nginx-mod-http-geoip-1.10.2-1.el6.x86_64 5/16
  128. Verifying : libXpm-3.5.10-2.el6.x86_64 6/16
  129. Verifying : nginx-mod-stream-1.10.2-1.el6.x86_64 7/16
  130. Verifying : nginx-all-modules-1.10.2-1.el6.noarch 8/16
  131. Verifying : nginx-mod-http-perl-1.10.2-1.el6.x86_64 9/16
  132. Verifying : nginx-mod-http-image-filter-1.10.2-1.el6.x86_64 10/16
  133. Verifying : nginx-1.10.2-1.el6.x86_64 11/16
  134. Verifying : geoipupdate-2.2.1-2.el6.x86_64 12/16
  135. Verifying : libxslt-1.1.26-2.el6_3.1.x86_64 13/16
  136. Verifying : nginx-filesystem-1.10.2-1.el6.noarch 14/16
  137. Verifying : gd-2.0.35-11.el6.x86_64 15/16
  138. Verifying : nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64 16/16
  139. Installed:
  140. nginx.x86_64 0:1.10.2-1.el6
  141. Dependency Installed:
  142. GeoIP.x86_64 0:1.6.5-1.el6 GeoIP-GeoLite-data.noarch 0:2016.07-1.el6 GeoIP-GeoLite-data-extra.noarch 0:2016.07-1.el6 gd.x86_64 0:2.0.35-11.el6 geoipupdate.x86_64 0:2.2.1-2.el6
  143. libXpm.x86_64 0:3.5.10-2.el6 libxslt.x86_64 0:1.1.26-2.el6_3.1 nginx-all-modules.noarch 0:1.10.2-1.el6 nginx-filesystem.noarch 0:1.10.2-1.el6 nginx-mod-http-geoip.x86_64 0:1.10.2-1.el6
  144. nginx-mod-http-image-filter.x86_64 0:1.10.2-1.el6 nginx-mod-http-perl.x86_64 0:1.10.2-1.el6 nginx-mod-http-xslt-filter.x86_64 0:1.10.2-1.el6 nginx-mod-mail.x86_64 0:1.10.2-1.el6 nginx-mod-stream.x86_64 0:1.10.2-1.el6
  145. Complete!

出现Complete后,说明已经成功安装啦。

2、启动

直接输入:service nginx start

Center

启动成功后,直接在浏览器输入主机ip地址:http://120.132.115.246/就可以访问了,不过80端口是需要备案的,有可能你刚刚开始可以访问,过一段时间就不能了,因为没有备案通过,你的80端口是会被封掉的。

Center 1

3、配置跳转

我们需要访问80后,跳转到Tomcat或者其他Web应用去,就需要修改一下Nginx的默认配置,简单的修改一下配置就好。

文件路径:/etc/nginx/conf.d/default.conf

将文件的内容替换为:

  1. #
  2. # The default server
  3. #
  4. server {
  5. listen 80 default_server;
  6. listen [::]:80 default_server;
  7. server_name _;
  8. root /usr/share/nginx/html;
  9. # Load configuration files for the default server block.
  10. include /etc/nginx/default.d/*.conf;
  11. location / {
  12. proxy_redirect off;
  13. proxy_set_header Host $host;
  14. proxy_set_header X-Real-IP $remote_addr;
  15. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  16. proxy_pass http://127.0.0.1:8080;
  17. }
  18. error_page 404 /404.html;
  19. location = /40x.html {
  20. }
  21. error_page 500 502 503 504 /50x.html;
  22. location = /50x.html {
  23. }
  24. }

其中proxy_pass http://127.0.0.1:8080为本机Tomcat应用的端口,也就是让连接跳转到Tomcat去

如果需要更多的转发,请参考: Linux上利用nginx域名转发

4、重启Nginx

配置好过后,直接重新启动Nginx

输入:service nginx reload

在浏览器访问我们的主机ip

Center 2

--——————————————————————————

成功!

发表评论

表情:
评论列表 (有 0 条评论,367人围观)

还没有评论,来说两句吧...

相关阅读