Linux yum 安装nginx
1、安装
直接运行: yum install nginx
[root@hzw-2312 ~]# yum install nginx
Loaded plugins: fastestmirror, presto
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 0:1.10.2-1.el6 will be installed
--> Processing Dependency: nginx-filesystem = 1.10.2-1.el6 for package: nginx-1.10.2-1.el6.x86_64
--> Processing Dependency: nginx-all-modules = 1.10.2-1.el6 for package: nginx-1.10.2-1.el6.x86_64
--> Processing Dependency: nginx-filesystem for package: nginx-1.10.2-1.el6.x86_64
--> Running transaction check
---> Package nginx-all-modules.noarch 0:1.10.2-1.el6 will be installed
--> Processing Dependency: nginx-mod-stream = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
--> Processing Dependency: nginx-mod-mail = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
--> Processing Dependency: nginx-mod-http-xslt-filter = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
--> Processing Dependency: nginx-mod-http-perl = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
--> Processing Dependency: nginx-mod-http-image-filter = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
--> Processing Dependency: nginx-mod-http-geoip = 1.10.2-1.el6 for package: nginx-all-modules-1.10.2-1.el6.noarch
---> Package nginx-filesystem.noarch 0:1.10.2-1.el6 will be installed
--> Running transaction check
---> Package nginx-mod-http-geoip.x86_64 0:1.10.2-1.el6 will be installed
--> Processing Dependency: GeoIP for package: nginx-mod-http-geoip-1.10.2-1.el6.x86_64
--> Processing Dependency: libGeoIP.so.1()(64bit) for package: nginx-mod-http-geoip-1.10.2-1.el6.x86_64
---> Package nginx-mod-http-image-filter.x86_64 0:1.10.2-1.el6 will be installed
--> Processing Dependency: gd for package: nginx-mod-http-image-filter-1.10.2-1.el6.x86_64
--> Processing Dependency: libgd.so.2()(64bit) for package: nginx-mod-http-image-filter-1.10.2-1.el6.x86_64
---> Package nginx-mod-http-perl.x86_64 0:1.10.2-1.el6 will be installed
---> Package nginx-mod-http-xslt-filter.x86_64 0:1.10.2-1.el6 will be installed
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.18)(64bit) for package: nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.11)(64bit) for package: nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64
--> Processing Dependency: libxslt.so.1()(64bit) for package: nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64
--> Processing Dependency: libexslt.so.0()(64bit) for package: nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64
---> Package nginx-mod-mail.x86_64 0:1.10.2-1.el6 will be installed
---> Package nginx-mod-stream.x86_64 0:1.10.2-1.el6 will be installed
--> Running transaction check
---> Package GeoIP.x86_64 0:1.6.5-1.el6 will be installed
--> Processing Dependency: geoipupdate for package: GeoIP-1.6.5-1.el6.x86_64
--> Processing Dependency: GeoIP-data for package: GeoIP-1.6.5-1.el6.x86_64
---> Package gd.x86_64 0:2.0.35-11.el6 will be installed
--> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-11.el6.x86_64
---> Package libxslt.x86_64 0:1.1.26-2.el6_3.1 will be installed
--> Running transaction check
---> Package GeoIP-GeoLite-data.noarch 0:2016.07-1.el6 will be installed
--> Processing Dependency: GeoIP-GeoLite-data-extra = 2016.07-1.el6 for package: GeoIP-GeoLite-data-2016.07-1.el6.noarch
---> Package geoipupdate.x86_64 0:2.2.1-2.el6 will be installed
---> Package libXpm.x86_64 0:3.5.10-2.el6 will be installed
--> Running transaction check
---> Package GeoIP-GeoLite-data-extra.noarch 0:2016.07-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================================================================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================================================================================================================================================================
Installing:
nginx x86_64 1.10.2-1.el6 epel 462 k
Installing for dependencies:
GeoIP x86_64 1.6.5-1.el6 epel 113 k
GeoIP-GeoLite-data noarch 2016.07-1.el6 epel 399 k
GeoIP-GeoLite-data-extra noarch 2016.07-1.el6 epel 25 M
gd x86_64 2.0.35-11.el6 base 142 k
geoipupdate x86_64 2.2.1-2.el6 epel 28 k
libXpm x86_64 3.5.10-2.el6 base 51 k
libxslt x86_64 1.1.26-2.el6_3.1 base 452 k
nginx-all-modules noarch 1.10.2-1.el6 epel 7.7 k
nginx-filesystem noarch 1.10.2-1.el6 epel 8.5 k
nginx-mod-http-geoip x86_64 1.10.2-1.el6 epel 14 k
nginx-mod-http-image-filter x86_64 1.10.2-1.el6 epel 16 k
nginx-mod-http-perl x86_64 1.10.2-1.el6 epel 26 k
nginx-mod-http-xslt-filter x86_64 1.10.2-1.el6 epel 16 k
nginx-mod-mail x86_64 1.10.2-1.el6 epel 43 k
nginx-mod-stream x86_64 1.10.2-1.el6 epel 36 k
Transaction Summary
==============================================================================================================================================================================================================================================================================
Install 16 Package(s)
Total download size: 27 M
Installed size: 58 M
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 27 M
(1/16): GeoIP-1.6.5-1.el6.x86_64.rpm | 113 kB 00:00
(2/16): GeoIP-GeoLite-data-2016.07-1.el6.noarch.rpm | 399 kB 00:00
(3/16): GeoIP-GeoLite-data-extra-2016.07-1.el6.noarch.rpm | 25 MB 00:02
(4/16): gd-2.0.35-11.el6.x86_64.rpm | 142 kB 00:00
(5/16): geoipupdate-2.2.1-2.el6.x86_64.rpm | 28 kB 00:00
(6/16): libXpm-3.5.10-2.el6.x86_64.rpm | 51 kB 00:00
(7/16): libxslt-1.1.26-2.el6_3.1.x86_64.rpm | 452 kB 00:00
(8/16): nginx-1.10.2-1.el6.x86_64.rpm | 462 kB 00:00
(9/16): nginx-all-modules-1.10.2-1.el6.noarch.rpm | 7.7 kB 00:00
(10/16): nginx-filesystem-1.10.2-1.el6.noarch.rpm | 8.5 kB 00:00
(11/16): nginx-mod-http-geoip-1.10.2-1.el6.x86_64.rpm | 14 kB 00:00
(12/16): nginx-mod-http-image-filter-1.10.2-1.el6.x86_64.rpm | 16 kB 00:00
(13/16): nginx-mod-http-perl-1.10.2-1.el6.x86_64.rpm | 26 kB 00:00
(14/16): nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64.rpm | 16 kB 00:00
(15/16): nginx-mod-mail-1.10.2-1.el6.x86_64.rpm | 43 kB 00:00
(16/16): nginx-mod-stream-1.10.2-1.el6.x86_64.rpm | 36 kB 00:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 960 kB/s | 27 MB 00:28
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : GeoIP-GeoLite-data-2016.07-1.el6.noarch 1/16
Installing : GeoIP-GeoLite-data-extra-2016.07-1.el6.noarch 2/16
Installing : nginx-filesystem-1.10.2-1.el6.noarch 3/16
Installing : libxslt-1.1.26-2.el6_3.1.x86_64 4/16
Installing : geoipupdate-2.2.1-2.el6.x86_64 5/16
Installing : GeoIP-1.6.5-1.el6.x86_64 6/16
Installing : libXpm-3.5.10-2.el6.x86_64 7/16
Installing : gd-2.0.35-11.el6.x86_64 8/16
Installing : nginx-mod-mail-1.10.2-1.el6.x86_64 9/16
Installing : nginx-mod-stream-1.10.2-1.el6.x86_64 10/16
Installing : nginx-mod-http-perl-1.10.2-1.el6.x86_64 11/16
Installing : nginx-mod-http-image-filter-1.10.2-1.el6.x86_64 12/16
Installing : nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64 13/16
Installing : nginx-1.10.2-1.el6.x86_64 14/16
Installing : nginx-mod-http-geoip-1.10.2-1.el6.x86_64 15/16
Installing : nginx-all-modules-1.10.2-1.el6.noarch 16/16
Verifying : GeoIP-GeoLite-data-extra-2016.07-1.el6.noarch 1/16
Verifying : GeoIP-GeoLite-data-2016.07-1.el6.noarch 2/16
Verifying : nginx-mod-mail-1.10.2-1.el6.x86_64 3/16
Verifying : GeoIP-1.6.5-1.el6.x86_64 4/16
Verifying : nginx-mod-http-geoip-1.10.2-1.el6.x86_64 5/16
Verifying : libXpm-3.5.10-2.el6.x86_64 6/16
Verifying : nginx-mod-stream-1.10.2-1.el6.x86_64 7/16
Verifying : nginx-all-modules-1.10.2-1.el6.noarch 8/16
Verifying : nginx-mod-http-perl-1.10.2-1.el6.x86_64 9/16
Verifying : nginx-mod-http-image-filter-1.10.2-1.el6.x86_64 10/16
Verifying : nginx-1.10.2-1.el6.x86_64 11/16
Verifying : geoipupdate-2.2.1-2.el6.x86_64 12/16
Verifying : libxslt-1.1.26-2.el6_3.1.x86_64 13/16
Verifying : nginx-filesystem-1.10.2-1.el6.noarch 14/16
Verifying : gd-2.0.35-11.el6.x86_64 15/16
Verifying : nginx-mod-http-xslt-filter-1.10.2-1.el6.x86_64 16/16
Installed:
nginx.x86_64 0:1.10.2-1.el6
Dependency Installed:
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
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
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
Complete!
出现Complete后,说明已经成功安装啦。
2、启动
直接输入:service nginx start
启动成功后,直接在浏览器输入主机ip地址:http://120.132.115.246/就可以访问了,不过80端口是需要备案的,有可能你刚刚开始可以访问,过一段时间就不能了,因为没有备案通过,你的80端口是会被封掉的。
3、配置跳转
我们需要访问80后,跳转到Tomcat或者其他Web应用去,就需要修改一下Nginx的默认配置,简单的修改一下配置就好。
文件路径:/etc/nginx/conf.d/default.conf
将文件的内容替换为:
#
# The default server
#
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
其中proxy_pass http://127.0.0.1:8080为本机Tomcat应用的端口,也就是让连接跳转到Tomcat去
如果需要更多的转发,请参考: Linux上利用nginx域名转发
4、重启Nginx
配置好过后,直接重新启动Nginx
输入:service nginx reload
在浏览器访问我们的主机ip
--——————————————————————————
成功!
还没有评论,来说两句吧...