CentOS 可以直接通过yum安装Nginx,现在就yum如何安装Nginx讲下流程
使用rpm命令添加源,如果没有事先添加源,执行yum install nginx会报错
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
访问http://nginx.org/packages/ ,有关于种系统的源,选择自己需要的
执行命令:
[root@VM_0_8_centos /]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpmRetrieving http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpmwarning: /var/tmp/rpm-tmp.ZBdJtm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEYPreparing... ################################# [100%]Updating / installing...1:nginx-release-centos-7-0.el7.ngx ################################# [100%][root@VM_0_8_centos /]#
有一个warning,这个warning我们先忽略,不影响安装
执行完上面命令后,会在 /etc/yum.repos.d/目录下添加一个Nginx.repo文件,如下查看
[root@VM_0_8_centos yum.repos.d]# cd /etc/yum.repos.d/[root@VM_0_8_centos yum.repos.d]# ls -latotal 60drwxr-xr-x. 2 root root 4096 Oct 11 15:21 .drwxr-xr-x. 89 root root 12288 Sep 20 14:20 ..-rw-r--r--. 1 root root 614 Sep 13 10:48 CentOS-Base.repo-rw-r--r-- 1 root root 1309 Aug 13 22:34 CentOS-CR.repo-rw-r--r-- 1 root root 649 Aug 13 22:34 CentOS-Debuginfo.repo-rw-r--r-- 1 root root 230 Sep 13 10:48 CentOS-Epel.repo-rw-r--r-- 1 root root 314 Aug 13 22:34 CentOS-fasttrack.repo-rw-r--r-- 1 root root 630 Aug 13 22:34 CentOS-Media.repo-rw-r--r-- 1 root root 1331 Aug 13 22:34 CentOS-Sources.repo-rw-r--r-- 1 root root 4768 Aug 13 22:34 CentOS-Vault.repo-rw-r--r-- 1 root root 664 May 11 11:35 epel-7.repo-rw-r--r-- 1 root root 113 Jul 15 2014 nginx.repo[root@VM_0_8_centos yum.repos.d]#
yum install nginx
[root@VM_0_8_centos yum.repos.d]# yum install nginxLoaded plugins: fastestmirror, langpacksRepository epel is listed more than once in the configurationDetermining fastest mirrorsepel | 3.2 kB 00:00:00extras | 3.4 kB 00:00:00os | 3.6 kB 00:00:00updates | 3.4 kB 00:00:00(1/5): epel/7/x86_64/group_gz | 88 kB 00:00:00(2/5): epel/7/x86_64/updateinfo | 948 kB 00:00:00(3/5): extras/7/x86_64/primary_db | 204 kB 00:00:00(4/5): epel/7/x86_64/primary | 3.6 MB 00:00:00(5/5): updates/7/x86_64/primary_db | 6.0 MB 00:00:00epel 12723/12723Resolving Dependencies--> Running transaction check---> Package nginx.x86_64 1:1.12.2-2.el7 will be installed--> Processing Dependency: nginx-filesystem = 1:1.12.2-2.el7 for package: 1:nginx-1.12.2-2.el7.x86_64--> Processing Dependency: nginx-all-modules = 1:1.12.2-2.el7 for package: 1:nginx-1.12.2-2.el7.x86_64--> Processing Dependency: nginx-filesystem for package: 1:nginx-1.12.2-2.el7.x86_64--> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.12.2-2.el7.x86_64--> Running transaction check---> Package gperftools-libs.x86_64 0:2.6.1-1.el7 will be installed---> Package nginx-all-modules.noarch 1:1.12.2-2.el7 will be installed--> Processing Dependency: nginx-mod-stream = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch--> Processing Dependency: nginx-mod-mail = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch--> Processing Dependency: nginx-mod-http-xslt-filter = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch--> Processing Dependency: nginx-mod-http-perl = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch--> Processing Dependency: nginx-mod-http-image-filter = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch--> Processing Dependency: nginx-mod-http-geoip = 1:1.12.2-2.el7 for package: 1:nginx-all-modules-1.12.2-2.el7.noarch---> Package nginx-filesystem.noarch 1:1.12.2-2.el7 will be installed--> Running transaction check---> Package nginx-mod-http-geoip.x86_64 1:1.12.2-2.el7 will be installed---> Package nginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7 will be installed--> Processing Dependency: gd for package: 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64--> Processing Dependency: libgd.so.2()(64bit) for package: 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64---> Package nginx-mod-http-perl.x86_64 1:1.12.2-2.el7 will be installed---> Package nginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7 will be installed--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.18)(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.11)(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64--> Processing Dependency: libxslt.so.1()(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64--> Processing Dependency: libexslt.so.0()(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64---> Package nginx-mod-mail.x86_64 1:1.12.2-2.el7 will be installed---> Package nginx-mod-stream.x86_64 1:1.12.2-2.el7 will be installed--> Running transaction check---> Package gd.x86_64 0:2.0.35-26.el7 will be installed--> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-26.el7.x86_64---> Package libxslt.x86_64 0:1.1.28-5.el7 will be installed--> Running transaction check---> Package libXpm.x86_64 0:3.5.12-1.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved==================================================================================================================================================================================================================Package Arch Version Repository Size==================================================================================================================================================================================================================Installing:nginx x86_64 1:1.12.2-2.el7 epel 530 kInstalling for dependencies:gd x86_64 2.0.35-26.el7 os 146 kgperftools-libs x86_64 2.6.1-1.el7 os 272 klibXpm x86_64 3.5.12-1.el7 os 55 klibxslt x86_64 1.1.28-5.el7 os 242 knginx-all-modules noarch 1:1.12.2-2.el7 epel 16 knginx-filesystem noarch 1:1.12.2-2.el7 epel 17 knginx-mod-http-geoip x86_64 1:1.12.2-2.el7 epel 23 knginx-mod-http-image-filter x86_64 1:1.12.2-2.el7 epel 26 knginx-mod-http-perl x86_64 1:1.12.2-2.el7 epel 36 knginx-mod-http-xslt-filter x86_64 1:1.12.2-2.el7 epel 26 knginx-mod-mail x86_64 1:1.12.2-2.el7 epel 54 knginx-mod-stream x86_64 1:1.12.2-2.el7 epel 76 kTransaction Summary==================================================================================================================================================================================================================Install 1 Package (+12 Dependent packages)Total download size: 1.5 MInstalled size: 4.3 MIs this ok [y/d/N]:
上面命令,最后一行Is this ok [y/d/N]:后面, 我们输入y,如果要跳过这个步骤,安装时执行yum install nginx -y
输入y后,命令继续执行如下
Is this ok [y/d/N]: yDownloading packages:(1/13): gd-2.0.35-26.el7.x86_64.rpm | 146 kB 00:00:00(2/13): libXpm-3.5.12-1.el7.x86_64.rpm | 55 kB 00:00:00(3/13): gperftools-libs-2.6.1-1.el7.x86_64.rpm | 272 kB 00:00:00(4/13): libxslt-1.1.28-5.el7.x86_64.rpm | 242 kB 00:00:00(5/13): nginx-all-modules-1.12.2-2.el7.noarch.rpm | 16 kB 00:00:00(6/13): nginx-filesystem-1.12.2-2.el7.noarch.rpm | 17 kB 00:00:00(7/13): nginx-mod-http-geoip-1.12.2-2.el7.x86_64.rpm | 23 kB 00:00:00(8/13): nginx-mod-http-image-filter-1.12.2-2.el7.x86_64.rpm | 26 kB 00:00:00(9/13): nginx-1.12.2-2.el7.x86_64.rpm | 530 kB 00:00:00(10/13): nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64.rpm | 26 kB 00:00:00(11/13): nginx-mod-http-perl-1.12.2-2.el7.x86_64.rpm | 36 kB 00:00:00(12/13): nginx-mod-mail-1.12.2-2.el7.x86_64.rpm | 54 kB 00:00:00(13/13): nginx-mod-stream-1.12.2-2.el7.x86_64.rpm | 76 kB 00:00:00------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total 3.0 MB/s | 1.5 MB 00:00:00Running transaction checkRunning transaction testTransaction test succeededRunning transactionWarning: RPMDB altered outside of yum.Installing : gperftools-libs-2.6.1-1.el7.x86_64 1/13Installing : libxslt-1.1.28-5.el7.x86_64 2/13Installing : 1:nginx-filesystem-1.12.2-2.el7.noarch 3/13Installing : libXpm-3.5.12-1.el7.x86_64 4/13Installing : gd-2.0.35-26.el7.x86_64 5/13Installing : 1:nginx-mod-mail-1.12.2-2.el7.x86_64 6/13Installing : 1:nginx-mod-http-geoip-1.12.2-2.el7.x86_64 7/13Installing : 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64 8/13Installing : 1:nginx-mod-http-perl-1.12.2-2.el7.x86_64 9/13Installing : 1:nginx-mod-stream-1.12.2-2.el7.x86_64 10/13Installing : 1:nginx-1.12.2-2.el7.x86_64 11/13Installing : 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64 12/13Installing : 1:nginx-all-modules-1.12.2-2.el7.noarch 13/13Verifying : libXpm-3.5.12-1.el7.x86_64 1/13Verifying : 1:nginx-filesystem-1.12.2-2.el7.noarch 2/13Verifying : gd-2.0.35-26.el7.x86_64 3/13Verifying : libxslt-1.1.28-5.el7.x86_64 4/13Verifying : gperftools-libs-2.6.1-1.el7.x86_64 5/13Verifying : 1:nginx-1.12.2-2.el7.x86_64 6/13Verifying : 1:nginx-mod-mail-1.12.2-2.el7.x86_64 7/13Verifying : 1:nginx-all-modules-1.12.2-2.el7.noarch 8/13Verifying : 1:nginx-mod-http-geoip-1.12.2-2.el7.x86_64 9/13Verifying : 1:nginx-mod-http-xslt-filter-1.12.2-2.el7.x86_64 10/13Verifying : 1:nginx-mod-http-image-filter-1.12.2-2.el7.x86_64 11/13Verifying : 1:nginx-mod-http-perl-1.12.2-2.el7.x86_64 12/13Verifying : 1:nginx-mod-stream-1.12.2-2.el7.x86_64 13/13Installed:nginx.x86_64 1:1.12.2-2.el7Dependency Installed:gd.x86_64 0:2.0.35-26.el7 gperftools-libs.x86_64 0:2.6.1-1.el7 libXpm.x86_64 0:3.5.12-1.el7 libxslt.x86_64 0:1.1.28-5.el7nginx-all-modules.noarch 1:1.12.2-2.el7 nginx-filesystem.noarch 1:1.12.2-2.el7 nginx-mod-http-geoip.x86_64 1:1.12.2-2.el7 nginx-mod-http-image-filter.x86_64 1:1.12.2-2.el7nginx-mod-http-perl.x86_64 1:1.12.2-2.el7 nginx-mod-http-xslt-filter.x86_64 1:1.12.2-2.el7 nginx-mod-mail.x86_64 1:1.12.2-2.el7 nginx-mod-stream.x86_64 1:1.12.2-2.el7Complete![root@VM_0_8_centos yum.repos.d]#
安装完成。
[root@VM_0_8_centos yum.repos.d]# whereis nginxnginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man3/nginx.3pm.gz /usr/share/man/man8/nginx.8.gz
Nginx配置路径为 /etc/nginx/
查看Nginx配置文件内容,执行命令cat /etc/nginx/nginx.conf
[root@VM_0_8_centos nginx]# cat /etc/nginx/nginx.conf# For more information on configuration, see:# * Official English Documentation: http://nginx.org/en/docs/# * Official Russian Documentation: http://nginx.org/ru/docs/user nginx;worker_processes auto;error_log /var/log/nginx/error.log;pid /run/nginx.pid;# Load dynamic modules. See /usr/share/nginx/README.dynamic.include /usr/share/nginx/modules/*.conf;events {worker_connections 1024;}http {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 /var/log/nginx/access.log main;sendfile on;tcp_nopush on;tcp_nodelay on;keepalive_timeout 65;types_hash_max_size 2048;include /etc/nginx/mime.types;default_type application/octet-stream;# Load modular configuration files from the /etc/nginx/conf.d directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.include /etc/nginx/conf.d/*.conf;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 / {}error_page 404 /404.html;location = /40x.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}}# Settings for a TLS enabled server.## server {# listen 443 ssl http2 default_server;# listen [::]:443 ssl http2 default_server;# server_name _;# root /usr/share/nginx/html;## ssl_certificate "/etc/pki/nginx/server.crt";# ssl_certificate_key "/etc/pki/nginx/private/server.key";# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 10m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;## # Load configuration files for the default server block.# include /etc/nginx/default.d/*.conf;## location / {# }## error_page 404 /404.html;# location = /40x.html {# }## error_page 500 502 503 504 /50x.html;# location = /50x.html {# }# }}[root@VM_0_8_centos nginx]#
通过nginx.conf文件,我们可以看到日志文件的路径
错误日志路径: /var/log/nginx/error.log
正常日志路径: /var/log/nginx/access.log
执行nginx,启动nginx
执行nginx -t命令测试,如下,测试成功
执行ps aux | grep nginx查看nginx是否启动成功
[root@VM_0_8_centos nginx]# nginx[root@VM_0_8_centos nginx]# nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful[root@VM_0_8_centos nginx]# ps aux | grep nginxroot 445 0.0 0.2 120792 2100 ? Ss 15:57 0:00 nginx: master process nginxnginx 446 0.0 0.3 123264 3552 ? S 15:57 0:00 nginx: worker processroot 546 0.0 0.0 112704 976 pts/0 R+ 15:58 0:00 grep --color=auto nginx[root@VM_0_8_centos nginx]#
nginx启动成功后,通过云服务器的IP访问,我们在浏览器看到这个页面

gcc版本老旧,经常会碰到的问题:/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found。不要在网上找各种方法,直接升级gcc吧
redis配置多个端口,redis启动多个实例
linux如何挂载新买的硬盘?
vim编辑nginx conf文件时,设置高亮/显示行号
vi/vim打开文件提示Found a swap file by the name
linux报错:C++ compiler too old, need g++ 4.9.4 or clang++ 3.4.2 (CXX=g++)
linux下如何安装nodejs
linux下安装 redis,以及相关使用
linux下通过yum安装mongodb
RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的“添加/删除程序
Ubuntu 16.04 发布时,一个引人注目的新特性便是 apt 命令的引入。其实早在 2014 年,apt 命令就已经发布了第一个稳定版,只是直到 2016 年的 Ubuntu 16.04 系统发布时才开始引人关注。随着 apt install package 命令的使用频率和普遍性逐步超过 apt-get install package,越来越多的其它 Linux 发行版也开始遵循 Ubuntu 的脚步,开始鼓励用户使用 apt 而不是 apt-get。
centos查看环境变量与设置环境变量在使用过程中很常见,本文整理了一些常用的与环境变量相关的命令,感兴趣的朋友可以参考下希望对你有所帮助
linux cenos下安装oh my zsh,oh my zsh 用于管理zsh配置,使shell界面更美观。 Zsh 是一款功能强大终端(shell)软件,既可以作为一个交互式终端,也可以作为一个脚本解释器。它在兼容 Bash 的同时 (默认不兼容,除非设置成 emulate sh) 还有提供了很多改进。
通过Nginx反向代理,在一个云服务器上绑定多个域名,不同的域名访问不同的目录,端口
如何在Linux(CentOS 7)上安装Nginx,作为反向代理服务器。
命令从指定点开始将 File 参数指定的文件写到标准输出。如果没有指定文件,那么会使用标准输入。Number 变量指定将多少单元写到标准输出。Number 变量的值可以是正的或负的整数。如果值的前面有 +(加号),从文件开头指定的单元数开始将文件写到标准输出。如果值的前面有 -(减号),那么从文件末尾指定的单元数开始将文件写到标准输出。如果值前面没有 +(加号)或 -(减号),那么从文件末尾指定的单元号开始读取文件