1 /etc/nginx/nginx.conf,在主配置下设置 /etc/nginx/conf.d/*.conf

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/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 /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

2 /etc/nginx/conf.d/ 下设置一个 default.conf,server_name 设置为 localhost,如果有其他非法域名 A 记录到该机器上,则返回默认的 Nginx 页面:

server {
listen 80;
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
root /usr/share/nginx/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 /usr/share/nginx/html;
4 https 与 websocket 配置实例:

upstream oone_api {
server 127.0.0.1:8000;
}

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

server {
listen 443;
server_name api.oone.com;

ssl on;
root /usr/share/nginx/html;
index index.html index.htm;

ssl_certificate /etc/nginx/sslkey/api.oone.com.crt;
ssl_certificate_key /etc/nginx/sslkey/api.oone.com.key;

ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
ssl_prefer_server_ciphers on;

#access_log /var/log/nginx/log/host.access.log main;

location /test/v2/ {
proxy_pass http:www.douniu178.com //oone_api/;
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;

client_max_body_size 10m;
client_body_buffer_size 128k;

proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;

proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
keepalive_timeout 30;
}

location /test/v2/websocket {
proxy_pass http://oone_api/websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}

location ^~ /to_closest_node/websocket {
internal;
proxy_pass http://$host/websocket;

proxy_buffering off;
proxy_method GET;
proxy_pass_request_body off;
proxy_max_temp_file_size 0;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}

location / {
root /usr/share/nginx/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 www.thd1956.com/ /50x.html;
5 前端静态文件站点与后端接口配置在同一个域名下:

server {
listen 80;
server_name oone.oone.com;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

root /var/oone/public;
index index.html index.htm;

location ^~ /api {
proxy_pass http://127.0.0.1:8000;
proxy_redirect off;
}

location / {
try_files $uri $uri/ /index.html;
}

#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 {

6 开启 gzip 以及根据不同的 host 做不同的跳转配置:

server {
listen 80;
server_name www.oone.com;
#开启 gzip 并且设置 gzip_type
gzip on;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/ www.huange157.com jpeg image/gif image/png;

#access_log /var/log/nginx/log/host.access.log main;

root /var/oone/dist;
index index.html index.htm;

# 根据不同的 host 做不同的跳转
location = /app {
if ($http_user_agent ~* (android)) {
rewrite ^ https://m.pp.cn/detail.html?appid=7658720&ch_src=pp_dev&ch=default redirect;
}
if ($http_user_agent ~* (iphone)) {
rewrite ^ https://itunes.apple.com/cn/app/nikki/id1214764672?mt=8 redirect;
}
}

location / {
try_files $uri $uri/ /index.html;
}

#error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/ www.chushiyl.cn nginx/html;
7 http 跳转到 https 实例(以部署私有 docker 仓库为例):

upstream docker-backend {
server 127.0.0.1:5000;
}

# 80 端口访问跳转到 443 端口
server {
server_name oone.oone.com;
listen 80;
return 301 https://$server_name$request_uri;
}

map $upstream_http_docker_distribution_api_version $docker_distribution_api_version {
'' 'registry/2.0';
}

server {
server_name oone.oone.com;
listen 443 ssl;

ssl_certificate /etc/letsencrypt/live/oone.oone.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/oone.oone.com/privkey.pem;

ssl_protocols TLSv1.1 TLSv1.2;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;

# disable any limits to www.dfgj729.com avoid HTTP 413 for large image uploads
client_max_body_size 0;

# required to avoid HTTP 411: see Issue #1486 (https://github.com/docker/docker/issues/1486)
chunked_transfer_encoding on;

location /v2 {
# Do not allow connections from docker 1.5 and earlier
# docker pre-1.6.0 did not properly set the user agent on ping, catch "Go *" user agents
if ($http_user_agent ~ "^(docker\www.douniu828.com/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*$" ) {
return 404;
}

## If $docker_distribution_api_version is empty, the header will not be added.
## See the map directive above where this variable is defined.
add_header 'Docker-Distribution-Api-Version' $docker_distribution_api_version always;

proxy_set_header Host $http_host; # required for docker client's sake
proxy_set_header X-Real-IP $remote_addr; www.fengshen157.com # pass on real client's IP
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 900;

proxy_pass http://docker-backend;
auth_basic "Docker Registry";
auth_basic_user_file /etc/nginx/auth/registry_passwd;

Nginx 线上配置实例的更多相关文章

  1. 如何有效的跟踪线上 MySQL 实例表和权限的变更

    介绍 从系统管理员或 DBA 的角度来讲, 总期望将线上的各种变更限制在一个可控的范围内, 减少一些不确定的因素. 这样做有几点好处: . 记录线上的库表变更; . 对线上的库表变更有全局的了解; . ...

  2. Springcloud及Git线上配置详解

    SpringCloud 这个阶段该如何学? 三层架构 + MVC 框架: Spring IOC AOP SpringBoot,新一代的JavaEE开发标准,自动装配 模块化~ all in one,代 ...

  3. Nginx负载均衡配置实例详解

    负载均衡是我们大流量网站要做的一个东西,下面我来给大家介绍在Nginx服务器上进行负载均衡配置方法,希望对有需要的同学有所帮助哦. 负载均衡 先来简单了解一下什么是负载均衡,单从字面上的意思来理解就可 ...

  4. Nginx负载均衡配置实例详解(转)

    负载均衡是我们大流量网站要做的一个东西,下面我来给大家介绍在Nginx服务器上进行负载均衡配置方法,希望对有需要的同学有所帮助哦. 负载均衡 先来简单了解一下什么是负载均衡,单从字面上的意思来理解就可 ...

  5. [转载]Nginx负载均衡配置实例详解

    负载均衡是我们大流量网站要做的一个东西,下面我来给大家介绍在Nginx服务器上进行负载均衡配置方法,希望对有需要的同学有所帮助哦. 负载均衡 先来简单了解一下什么是负载均衡,单从字面上的意思来理解就可 ...

  6. Nginx负载均衡配置实例

    面对高并发的问题,企业往往会从两个方面来解决.其一,从硬件上面,提升硬件的配置,增加服务器的性能:另外,就是从软件上,将数据库和WEB服务器分离,使数据库和WEB服务器都能够充分发挥各自的性能,并且二 ...

  7. Apache2.2+php5.4在windows上配置实例

    这几天一直在win8.1上配置apache+php环境,网上看了很多文章,自己又犯了很多错误才配置成功,对新手来说真是有点小难. 自己打算把配置的详细过程写下来,好帮助其他新手快速配置. 在这里参考了 ...

  8. nginx反向代理配置实例分享

    nginx反向代理配置一例. 配置内容如下: user www www; worker_processes 8; error_log /usr/local/webserver/nginx/logs/n ...

  9. Nginx负载均衡配置实例(转)

    1.轮询 轮询即Round Robin,根据Nginx配置文件中的顺序,依次把客户端的Web请求分发到不同的后端服务器.配置的例子如下: http{ upstream sampleapp { serv ...

随机推荐

  1. Markdown 版本演进

    本文作为 Markdown 系列的第二篇,对上一篇使用 Markdown 写技术博客,我踩过的 6个坑博客提到的版本变迁进行简要的提纲说明. 如果不想读文章,请直接看思维导图,使用 Atom + ma ...

  2. django(新增model)No migrations to apply.

    django 1.8版本,在models下新建一个class,无法在数据库创建新表的问题: - models.py class HostPwd(models.Model): hostname = mo ...

  3. 03_set slice的时间复杂度

    set slice O(n+k) 使用切片赋值来解释set slice的时间复杂度 (1) 对li[0:3]赋值首先会删除1,2,3,空出来的位置被后面的元素依次向前移动填充,由del slice 得 ...

  4. go 运行项目

    此时运行项目,不能像之前简单的使用go run main.go,因为包main包含main.go和router.go的文件,因此需要运行go run *.go命令编译运行.如果是最终编译二进制项目,则 ...

  5. 手动搭建一个webpack+react笔记

    { "name": "lottery", "version": "1.0.0", "description&q ...

  6. nginx模块学习

    rewrite模块的语法 链接

  7. 设计与实现分离——面向接口编程(OO博客第三弹)

    如果说继承是面向对象程序设计中承前启后的特质,那么接口就是海纳百川的体现了.它们都是对数据和行为的抽象,都是对性质和关系的概括.只不过前者是纵向角度,而后者是横向角度罢了.今天呢,我想从设计+语法角度 ...

  8. 20172325 2016-2017-2 《Java程序设计》第四周学习总结

    20172325 2016-2017-2 <Java程序设计>第四周学习总结 教材学习内容总结 1.对类.对象.声明变量的定义和属性有了进一步的了解 2.学会如何编写一个类并运用到需要的程 ...

  9. java BufferedWriter写数据不完全

    package com.brucekun.keyword; import java.io.BufferedReader; import java.io.BufferedWriter; import j ...

  10. vue 过渡效果

    Vue中提供了`<transition>`和`<transition-group>`来为元素增加过渡动画.文档写的很清楚,但是实际使用起来还是费了一番功夫.这里做一个简单的记录 ...