Nginx在Windows 10、Ubuntu16.04、Centos7下的安装
本博文介绍Nginx在Windows 10、Ubuntu16.04、Centos7下的安装方法
一. Windows 10 安装nginx
在Windows下安装相对简单,只需要下载安装包,解压即可。
1.下载安装包
http://nginx.org/en/download.html,选择Stable version(最新的稳定版本)下载
2.解压安装
右键ngin-1.16.0.zip-->解压到当前文件夹
得到如下文件夹
3.启动
进入解压后的文件夹nginx-1.16.0,双击nginx.exe启动nginx服务器
4.测试
浏览器输入localhost:80或者localhost,看到Welcome to nginx为安装成功。
二. Ubuntu16.04 安装apt nginx
1.安装必要的包
sudo apt install curl gnupg2 ca-certificates lsb-release
2.设置apt仓库安装最新稳定版本的nginx,执行以下命令
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
3.导入官方签名密钥
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
4.验证key
sudo apt-key fingerprint ABF5BD827BD9BF62
执行后会有如下输出
pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
uid [ unknown] nginx signing key <signing-key@nginx.com>
5.安装nginx
sudo apt update
sudo apt install nginx
6.启动nginx
service nginx start
7.测试
浏览器输入ip:80或主机名称:80
三. Centos7 yum安装nginx
1.安装必要的包
sudo yum install yum-utils
2.新建nginx.repo文件
sudo nano /etc/yum.repos.d/nginx.repo
nginx.repo文件内容如下:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
4.安装nginx
sudo yum install nginx
5.启动nginx
sudo service nginx start
6.测试
四. ubuntu/centos编译安装nginx
说明:
安装使用的是阿里云ECS ubuntu14.04系统。操作过程中可能不同版本系统,会有些差异。具体问题还请网上查询相关解决办法。相关源码包会不断更新,假如看到本文时间比较久,还是建议直接上官网下载最近的版本。linux下手动编译安装用户软件,源码放在/usr/local/src中,安装路径在/usr/local/下。
准备阶段:
安装nginx的依赖包
1.安装编译需要用到的库和工具
apt-get install build-essential libtool gcc automake autoconf make
2.安装pcre,支持重写rewrite功能
源码下载地址:https://ftp.pcre.org/pub/pcre/
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.gz
tar -zxvf pcre-8.40.tar.gz
cd pcre-8.40.tar.gz
./configure
make && make install
3.安装zlib, 支持gzip压缩
源码下载地址:http://zlib.net
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make && make install
4.安装ssl
源码地址:https://www.openssl.org/source/
wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz
tar -zxvf openssl-1.0.2o.tar.gz
cd openssl-1.0.2o
./config
make && make install
安装运行NIGINX:
- 下载nginx源码
源码地址:http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.13.12.tar.gz
tar -zxvf nginx-1.13.12.tar.gz
cd nginx-1.13.12
./configure --prefix=/usr/local/nginx
make && make install
root@haima-PC:/usr/local/nginx/conf/conf.d# nginx -v
nginx version: nginx/1.13.12 //看到这个就说明已经成功了
root@haima-PC:/usr/local/nginx/conf# tree
.
├── fastcgi.conf
├── fastcgi.conf.default
├── fastcgi_params
├── fastcgi_params.default
├── koi-utf
├── koi-win
├── mime.types
├── mime.types.default
├── nginx.conf
├── nginx.conf_bak
├── nginx.conf.default
├── scgi_params
├── scgi_params.default
├── uwsgi_params
├── uwsgi_params.default
└── win-utf
1 directory, 17 files
nginx.conf 为配置文件
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include /usr/local/nginx/conf/conf.d/*.conf;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
新建conf.d/php.hm
文件夹
server{
listen 80;
server_name php.hm;
access_log /var/log/nginx/php.hm.access.log;
#access_log /data/logs/nginx/php.hm.access.log main;
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php {
root /wwwroot/test;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $DOCUMENT_ROOT$fastcgi_script_name;
include fastcgi_params;
}
}
配置域名
vim /etc/hosts
127.0.0.1 php.hm
常用命令
nginx -t
./sbin/nginx
nginx -s reload
nginx -s stop
Nginx在Windows 10、Ubuntu16.04、Centos7下的安装的更多相关文章
- Ubuntu16.04 LTS下apt安装WireShark
Ubuntu16.04 LTS下apt安装WireShark 安装与配置 首先通过apt安装WireShark: $ sudo apt install wireshark 会同时安装许多的依赖包,其中 ...
- Ubuntu16.04 Linux 下无痛安装、配置Gogs
本文在Win7+VMware的ubuntu 16.04中测试,安装Gogs,Install from binary. 准备工作: sudo apt-get install git sudo addus ...
- Ubuntu16.04/centos7 下为chrome/firefox安装flash player插件
为chrome安装flash: 打开终端,输入:sudo apt-get install pepperflashplugin-nonfree 或官网下载安装google-chrome-stable 为 ...
- Ubuntu16.04 Liunx下同时安装Anaconda2与Anaconda3
先根据Ubuntu预装的python2.7来安装Anaconda2,然后将Anaconda3作为其环境安装在envs文件夹下. 重要提示:有一些软件需要py2.7的环境,比如XX-Net, 最好是先安 ...
- Linux 下安装Nginx两种方法- yum安装 and Centos7下yum安装配置nginx与php
转载csdn: Linux 下安装Nginx两种方法- yum安装_在电脑前深思的博客-CSDN博客 Linux安装Nginx(两种方式)_HHRunning的博客-CSDN博客_linux 是否安装 ...
- 保姆级教程——Ubuntu16.04 Server下深度学习环境搭建:安装CUDA8.0,cuDNN6.0,Bazel0.5.4,源码编译安装TensorFlow1.4.0(GPU版)
写在前面 本文叙述了在Ubuntu16.04 Server下安装CUDA8.0,cuDNN6.0以及源码编译安装TensorFlow1.4.0(GPU版)的亲身经历,包括遇到的问题及解决办法,也有一些 ...
- chrome headless+selenium+python+(ubuntu 16.04/centos7) 下的实现
Ubuntu 16.04 下: 0x01 安装chrome 1 下载源加入系统源列表 sudo wget http://www.linuxidc.com/files/repo/google-chrom ...
- centos7 下 yum 安装Nginx
centos7 下 yum 安装和配置 Nginx 添加yum源 Nginx不在默认的yum源中,可以使用epel或者官网的yum源,这里使用官网的yum源 rpm -ivh http://nginx ...
- Ubuntu16.04环境下的硬盘挂载
需求:在Ubuntu16.04系统下,挂载一个新的硬盘 第一步:查看目前已经存在的分区的状态 命令:df -l 如上图所示,并未看到要挂载的硬盘(sda)的状态. 第二步:查看计算机硬盘的状态(包括格 ...
- 阿里云ECS服务器环境搭建——ubuntu16.04图形界面的安装
阿里云ECS服务器环境搭建——ubuntu16.04图形界面的安装 最近琢磨着想在服务器上搭建一个hexo博客,于是就在阿里云上买了一个云服务器ECS,远程接入后默认给的是一个命令窗口,没有图形界面, ...
随机推荐
- Java封装xml格式参数请求第三方接口
Java封装xml格式参数请求第三方接口 1.引用包 import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers ...
- Scala打印输出
1 package com.atguigu.chapter02 2 object TestCharType { 3 def main(args: Array[String]): Unit = { 4 ...
- C++ 线程安全的队列
无界队列 #include<queue> #include<mutex> #include<condition_variable> #include<opti ...
- 可能有人听过ThreadLocal,但一定没人听过ThreadLocal对象池
目录 简介 ThreadLocal ThreadLocalMap Recycler 总结 简介 JDK中的Thread大家肯定用过,只要是用过异步编程的同学肯定都熟悉.为了保存Thread中特有的变量 ...
- [一本通1681]统计方案 题解(Meet in mid与逆元的结合)
题目描述 小\(B\)写了一个程序,随机生成了\(n\)个正整数,分别是\(a[1]-a[n]\),他取出了其中一些数,并把它们乘起来之后模\(p\),得到了余数\(c\).但是没过多久,小\(B\) ...
- DevEco Studio 3.1差异化构建打包,提升多版本应用开发效率
原文:https://mp.weixin.qq.com/s/8XtgZ-k0mGXCjKHfSXFoOg,点击链接查看更多技术内容. HUAWEI DevEco Studio是开发Harmo ...
- CentOS GNOME桌面下安装截图工具gnome-screenshot
CentOS GNOME桌面下安装截图工具gnome-screenshot 1.光盘安装 (1).把镜像光盘放进电脑 (2).切换到 Packages (3).[root@localhost Pack ...
- CentOS 6.5编译安装httpd-2.4.7
CentOS 6.5编译安装httpd-2.4.7 CentOS 编译安装 Apache 2.4 准备: [root@NFSServer ~]# yum groupinstall "Deve ...
- c# 多线程传值注意的地方
前言 下面介绍多线程传值的几种方式,并说明注意点. 正文 static void Main(string[] args) { SampleTread thead = new SampleTread(1 ...
- lattice的ip不显示,如何解决
最近ip服务器可能会遇到问题,建议客户把更新检查关掉.我们有对应的IP下载链接. diamond在 https://www.latticesemi.com/ispupdate/ipexpr ...