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. 关于Python解释器

    由于Python语言从规范到解释器都是开源的,所以理论上任何人都可以编写Python解释器来执行Python代码 目前存在以下几种主流的Python解释器 CPython CPython是官方版本的解 ...

  2. (转)git clone: error: RPC failed; result=18, HTTP code = 200 解决办法

    git clone: error: RPC failed; result=18, HTTP code = 200 解决办法 分类: git2013-09-01 17:03 10753人阅读 评论(2) ...

  3. Hive 将本地数据导入hive表中

    # 导入 load data local inpath '/root/mr/The_Man_of_Property.txt' insert into table article; # 提示 FAILE ...

  4. 【Spring和SpringMVC】自动扫描注解类的问题

    尊重原创原文链接:http://blog.csdn.net/u014277445/article/details/52282697 Spring MVC项目中通常会有二个配置文件,spring-ser ...

  5. [转]构建Python+Selenium2自动化测试环境(二)

    构建Python+Selenium2自动化测试环境完成之后,就需要测试支持python的selenium的版本是否都支持在不同浏览器上运行,当前我们分别在三个最通用的浏览器上通过脚本来测试. 1.在I ...

  6. windows liver writer下载地址

    wlsetup-all.exe 链接:http://pan.baidu.com/s/1bo9pm7X 密码:zchb wlsetup-all简体版.exe 链接:http://pan.baidu.co ...

  7. CentOS6.5的安装及忘记root密码的措施

    CentOS6.5的安装及忘记root密码的措施 VMware虚拟机的配置 1.文件->新建->自定义->下一步 2.选择稍后安装操作系统 我们将采用自定义安装,杜绝VMware的一 ...

  8. c#笔记2019-01-06

    using System; using System.Collections.Generic; using System.Linq; using System.Text; /*2019-01-06C# ...

  9. HDU 3271 SNIBB

    SNIBB Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 3271 ...

  10. Laya List翻页滚动方案 & List滚动源码解析

    Laya List翻页滚动方案 & List滚动源码解析 @author ixenos 2019-03-29 1.List翻页滚动方案 /** * 计算下一页的起始索引, 不足时补足 * @p ...