nginx配置初步

1,切换至nginx目录,找到配置文件目录

cd /etc/nginx/conf.d

2,拷贝一份conf文件

sudo cp default.conf head.conf

3,进行conf文件的配置

server{
listen 80;
server_name head.cmbc.com.cn;
proxy_intercept_errors on;
error_page 404 403 401 /error/40x.html;
location / {
proxy_pass http://127.0.0.1:9100;
include proxy.conf;
} }

4,进行nginx配置测试

sudo nginx -t

5,进行nginx重新启动

sudo nginx -s reload

6,查看上一级目录中的配置

cd ..

cat nginx.conf

user www;
worker_processes 2; #pid logs/nginx.pid;
events{
worker_connections 1024;
} http{
include mine.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_forworded_for" "$request_time"'; access_log /var/log/nginx/access.log main; sendfile on;
keepalive_timeout 65; gzip on;
gzip_static on;
gzip_vary on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_disable "MSIE [1-6]\.";
gzip_comp_level 5;
gzip_min_length 1000;
gzip_buffers 4 16k;
gzip_types text/plain application/javascript text/javascript application/x-javascript text/css text/xml; include conf.d/*.conf; #这句就说明包含了conf.d下面所有的conf文件 }

7, 动静分离

server{
listen 80;
server_name s100;
access_log off; location ~* \.(png|html|js|css)$ {
proxy_pass http://statics;
#所有以.png .html .js .css结尾的url进入此路径
}
location / {
proxy_pass http://tomcats;
#其它url进入此路径
}
} server {
listen 80;
server_name pdb.tinyspace.cn;
index index.html;
add_header via $upstream_addr; location / {
proxy_pass http://localhost:8082;
include proxy.conf;
}
location /admin {
proxy_pass http://localhost:8082;
include proxy.conf;
}
location ~* \.(html|jpg|jpeg|png|css|scss|sass|js|tpl|ico)$ {
root /app/src/main/webapp/;
}
} # proxy.conf:
proxy_redirect off;
proxy_set_header Host $host;
client_max_body_size 15m;

这个要看:https://www.cnblogs.com/IPYQ/p/7889399.html

本地运行项目,有context情况下的配置,使用alias或者rewrite方式:

    server {
listen 9090;
#location ^~ /context/ajax/ {
# proxy_pass http://127.0.0.1:8080;
# proxy_redirect off;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#}
#location ^~ /trade/ {
# expires 0;
# alias /workspace/app/src/main/webapp/;
#}
location ^~ /context/ajax/ {
proxy_pass http://127.0.0.1:8080;
include proxy.conf;
}
location ^~ /webapp/ {
root /workspace/app/src/main/;
}
location ~* ^/context/(aaa|js|css|images|page)/ {
rewrite /context/(.*) /webapp/$1 last;
#alias /workspace/app/src/main/webapp/;
}

代理tcp协议连接mysql等

https://www.cnblogs.com/heruiguo/p/8962243.html#_label2_0

https://www.cnblogs.com/guogangj/p/5207104.html

events {
}
http {
}
stream { upstream cloudsocket {
hash $remote_addr consistent;
# $binary_remote_addr;
server 192.168.182.155:3306 weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 3306;#数据库服务器监听端口
proxy_connect_timeout 10s;
proxy_timeout 300s;#设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
proxy_pass cloudsocket;
}
}

客户端请求之后,出现resource interpreted as stylesheet but transferred with mime type text/plain <URL> 问题

注意,在http模块中保留

include            mime.types;
default_type application/octet-stream;
使用jquery的append方式写入css文件,注意在chrome调试的时候选中Disable cache;

nginx配置初步的更多相关文章

  1. Nginx配置杂记(转)

    转至:http://www.cnblogs.com/kuangke/p/5619400.html Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器,相较 ...

  2. nginx配置反向代理或跳转出现400问题处理记录

    午休完上班后,同事说测试站点访问接口出现400 Bad Request  Request Header Or Cookie Too Large提示,心想还好是测试服务器出现问题,影响不大,不过也赶紧上 ...

  3. Windos环境用Nginx配置反向代理和负载均衡

    Windos环境用Nginx配置反向代理和负载均衡 引言:在前后端分离架构下,难免会遇到跨域问题.目前的解决方案大致有JSONP,反向代理,CORS这三种方式.JSONP兼容性良好,最大的缺点是只支持 ...

  4. Windows下Nginx配置SSL实现Https访问(包含证书生成)

    Vincent.李   Windows下Nginx配置SSL实现Https访问(包含证书生成) Windows下Nginx配置SSL实现Https访问(包含证书生成) 首先要说明为什么要实现https ...

  5. Nginx 配置简述

    不论是本地开发,还是远程到 Server 开发,还是给提供 demo 给人看效果,我们时常需要对 Nginx 做配置,Nginx 的配置项相当多,如果考虑性能配置起来会比较麻烦.不过,我们往往只是需要 ...

  6. Nginx配置详解

    序言 Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的.从2004年发布至今,凭借开源的力量,已经接近成熟与完善. Nginx功能丰富,可作为HTTP服务器,也 ...

  7. Nginx配置Https

    1.申请证书: https://console.qcloud.com/ssl?utm_source=yingyongbao&utm_medium=ssl&utm_campaign=qc ...

  8. nginx配置为windows服务中的坑

    网上搜索“nginx 配置为windows服务”,很容易搜索到使用windows server warpper来配置,于是按照网上的方法我从github上的链接下载了1.17版本,前面都很顺利,很容易 ...

  9. 【nginx配置】nginx做非80端口转发

    一个场景 最近在使用PHP重写一个使用JAVA写的项目,因为需要查看之前的项目,所以要在本地搭建一个Tomcat来跑JAVA的项目.搭建成功后,因为Tomcat监听的端口是8080,因此,访问的URL ...

随机推荐

  1. cache控制器取值从TCM/CACHE/FLASH

    cache 控制器顶层有4组接口,分别为输入I/D bus ,输出TCM bus /Cache bus /direct flash bus (走cache ID bus matrix) flash 控 ...

  2. Python函数的装饰器

    函数的装饰器. 1. 装饰器 开闭原则: 对功能的扩展开放 对代码的修改是封闭 通用装饰器语法: def wrapper(fn): def inner(*args, **kwargs): # 聚合 & ...

  3. Python9-迭代器-生成器-day13

    迭代器# print('__iter__' in dir(int))# print('__iter__' in dir(list))# print('__iter__' in dir(dict))# ...

  4. H.264 与 MPEG-4 压缩格式的变革

    h.264 和 mpeg-4 的关系: h.264 /avc ( advanced video coding )标准,是 mpeg-4 的第 10 部分. mpeg-4的初衷是将dvd质量的图像码流从 ...

  5. 基础训练 Sine之舞

    Sine之舞 #include<iostream> #include<vector> #include<string.h> using namespace std; ...

  6. 关于priority_queue的一些说明

    参考GGBeng 相关定义 优先队列容器与队列一样,只能从队尾插入元素,从队首删除元素.但是它有一个特性,就是队列中最大的元素总是位于队首,所以出队时,并非按照先进先出的原则进行,而是将当前队列中最大 ...

  7. Linux下安装MySQLdb模块(Python)

    一.MySQLdb-python模块 https://pypi.python.org/pypi/MySQL-python ` 二.安装依赖包 yum -y install python-devel m ...

  8. 如何反馈问题issue?

    如何反馈问题issue? 01,请提交的时候换位思考一下:如果别人给你提交一个这样的 Issue,你能快速准确的理解吗?如果不能,烦请重新整理你的语言,按照要求的格式填写.专业一点,减少不必要的口舌浪 ...

  9. Java异常架构图及面试题---https://www.cnblogs.com/gaoweixiao99/p/4905860.html

    https://www.cnblogs.com/gaoweixiao99/p/4905860.html 红色为检查异常,就是eclipse要提示你是try catch 还是throws. 非检查异常, ...

  10. IndiaHacks 2nd Elimination 2017 (unofficial, unrated mirror, ICPC rules)

    D. Airplane Arrangements time limit per test 2 seconds memory limit per test 256 megabytes input sta ...