nginx

web服务 apache iis
django web框架
lvs 负载均衡 章文嵩博士
vue 尤雨溪
Tengine
F5 硬件负载
A10

安装

```
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar xf nginx-1.16.1.tar.gz
cd nginx-1.16.1
yum install gcc zlib2-devel pcre-devel openssl-devel
./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_stub_status_module
make && make install
```

目录结构

```
[root@localhost nginx]#ls
conf html logs sbin
conf 配置文件
html 存放静态文件 index.html 是默认的欢迎页面
logs 日志目录
sbin 二进制文件
启动以后会生成一个主进程,根据配置文件的选项来生成子进程(工作进程),主进程不负责处理用户的请求,用来转发用户的请求,真正负责处理用户请求的是子进程
```

命令格式

```
./sbin/nginx -h
nginx version: nginx/1.16.1
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives] Options:
-?,-h : this help
-v : show version and exit 显示版本号
-V : show version and configure options then exit 显示版本+编译时选项
-t : test configuration and exit 测试配置文件
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /opt/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file
```

配置文件

```shell
#user nobody; 使用哪个用户来启动子进程
worker_processes 1; #工作进程的个数,配置成cpu的核心数-1或者-2
# cpu亲缘性绑定,让nginx的子进程工作在哪个核心上 #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
#use [epoll|select|poll];
worker_connections 102400; # 每一个子进程可以处理的连接数
} 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; server {
listen 80; #监听端口
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html; # 指定静态文件地址
index index.html index.htm; # 指定默认的index页面
}
# 错误页面 找不到页面
#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;
# }
#} } ```

404页面

```
error_page 404 /404.html;
```

root和alias的区别

```
location /img {
  root /data/img;
}
root /data/img 里面必须有/img
location /img {
  alias /data/img;
}
alias /data/img 里面不需要有 /img
```

域名

```
server_name mynginx.com
```

多域名访问

```
server {
  listen 80;
  server_name www.taobao.com taobao.com;
  location / {
    root /data/taobao;
    index index.html;
  }
}
server {
  listen 80;
  server_name www.jd.com jd.com;
  location / {
    root /data/jd;
    index index.html;
  }
}
```

默认server

```
listen 80 default_server; #放在server中的端口号后面,在使用ip访问时,默认访问的server
```

Nginx安装、多域名访问的更多相关文章

  1. nginx禁止未绑定域名访问 并且强行断开连接

    总有些人,会把自己的域名绑到你的主机上. 出于什么原因,我没想到,但你肯定不愿意别人这么做. 在nginx中,用以下代码,配置一个默认主机. server { listen 80 default_se ...

  2. Nginx (安装+ 配置域名+ 访问认证 +发布文件)

    一.Nginx介绍: Nginx是一款高性能的HTTP和反向代理服务器,能够选择高效的epoll(linux2.6内核).kqueue(freebsd).eventport(solaris10)作为网 ...

  3. nginx 只允许域名访问,禁止IP访问

    在nginx中为了防止,通过ip地址或者没有备案的域名代理到nginx上,可以在nginx中配置来阻止这一操作 #只可以用域名访问(此处的server是新增,并不是在原有的server基础上修改),默 ...

  4. nginx只允许域名访问,禁止ip访问

    背景:为什么要禁止ip访问页面呢?这样做是为了避免其他人把未备案的域名解析到自己的服务器IP,而导致服务器被断网,我们可以通过禁止使用ip访问的方法,防止此类事情的发生. 解决方法:这里介绍修改配置文 ...

  5. nginx在基于域名访问的时候是下载的界面

    刚才在做nginx实验时候出现访问域名的时候是下载页面一直下载了好多文件,使用IP访问就正常,在配置文件中找到一个sendfile的参数,把参数值改为off或者直接注释掉这个参数就可以访问了.

  6. nginx只允许域名访问,禁止ip访问 禁止其他域名访问

    背景:为什么要禁止ip访问页面呢?这样做是为了避免其他人把未备案的域名解析到自己的服务器IP,而导致服务器被断网,我们可以通过禁止使用ip访问的方法,防止此类事情的发生. 解决方法:这里介绍修改配置文 ...

  7. Linux 学习笔记 6 搭建nginx 实现二级域名访问

    前言 在前一节的内容里面,我们学习了如何使用yum 包管理工具来安装我们需要的软件,这节内容,通过搭建Nginx 反向代理服务器,以及学习服务的配置等内容. NGINX Nginx是一款轻量级的Web ...

  8. centos nginx server_name 配置域名访问规则

    今天配置Server_name时,希望禁用一些域名,应为这些域名我想让通过另外一个Server配置 server_name "~^((\w*[^w]{1}\w*)|w{1,2})\.hell ...

  9. nginx安装配置域名转发

    1.安装pcre 1.[root@localhost home]# tar zxvf pcre-8.10.tar.gz //解压缩 2.[root@localhost home]# cd pcre-8 ...

  10. nginx安装及配置访问本地文件

    第一步安装nginx windows可以直接去官网下载,解压就能用 http://nginx.org/en/download.html ubuntu用命令行 sudo apt-get install ...

随机推荐

  1. 不可思议的hexo,五分钟教你免费搭一个高逼格技术博客

    引言 作为程序员拥有一个属于自己的个人技术博客,绝对是百利无一害的事,不仅方便出门装b,面试时亮出博客地址也会让面试官对你的好感度倍增.经常能在很多大佬的技术文章的文末,看到这样一句话: " ...

  2. java面试基础篇-List

    一.ArrayList: 底层为数组实现,线程不安全,查询,修改快,增加删除慢, 数据结构:数组以0为下标依次连续进行存储 数组查询元素:根据下标查询就行 数组增加元素:如果需要给index为10的位 ...

  3. C#是什么?

    C# 是一个现代的.通用的.面向对象的编程语言,它是由微软(Microsoft)开发的,由 Ecma 和 ISO 核准认可的. C# 是由 Anders Hejlsberg 和他的团队在 .Net 框 ...

  4. 迁移桌面程序到MS Store(15)——通过注册表开启Developer Mode

    没想到该系列不仅没有太监,还打算更新一个小短篇.在各种大厂小厂工作的各位想必都知道Windows域的概念.入域的机器很多的设置就由不得当前登入所使用的域账号了,Windows的更新和安全等众多的设置均 ...

  5. 惊呆了!不改一行 Java 代码竟然就能轻松解决敏感信息加解密|原创

    前言 出于安全考虑,现需要将数据库的中敏感信息加密存储到数据库中,但是正常业务交互还是需要使用明文数据,所以查询返回我们还需要经过相应的解密才能返回给调用方. ps:日常开发中,我们要有一定的安全意识 ...

  6. M - 诡异的楼梯 HDU - 1180(BFS + 在某个点等待一下 / 重复走该点)

    M - 诡异的楼梯 HDU - 1180 Hogwarts正式开学以后,Harry发现在Hogwarts里,某些楼梯并不是静止不动的,相反,他们每隔一分钟就变动一次方向. 比如下面的例子里,一开始楼梯 ...

  7. Appium自动化 - 设置unicodeKeyboard: True运行脚本后,手机输入时无法调出软键盘

    问题背景 做appium自动化的时候,使用了UiAutomator1驱动,然后设置了UnicodeKeyboard 执行自动化脚本之后,玩手机的时候发现平时用的输入法键盘没法调出来了 'automat ...

  8. radio 单选按钮 选中多个

    <input type="radio" name="a"/> <input type="radio" name=" ...

  9. Linux基础:Day06

    网路安全介绍背景: 早起的互联网 -- 1980年代 ,我们需要共享数据,传输数据:所传输或者共享的数据均为明文: 随着互连网发展,安全称为了国家的一种战略资源: 我们做的,比如编程,运维 -- 手工 ...

  10. Mac下Web切图常用PS快捷命令

    Mac下 Z 放大镜 双击放大镜   图片会回到100%大小 C 切片工具 B 画笔    alt 在B模式下 吸取颜色 M   选区(默认) 点击第二次M   矩形选区 可以固定大小 shift+c ...