nginx配置初步
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配置初步的更多相关文章
- Nginx配置杂记(转)
转至:http://www.cnblogs.com/kuangke/p/5619400.html Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器,相较 ...
- nginx配置反向代理或跳转出现400问题处理记录
午休完上班后,同事说测试站点访问接口出现400 Bad Request Request Header Or Cookie Too Large提示,心想还好是测试服务器出现问题,影响不大,不过也赶紧上 ...
- Windos环境用Nginx配置反向代理和负载均衡
Windos环境用Nginx配置反向代理和负载均衡 引言:在前后端分离架构下,难免会遇到跨域问题.目前的解决方案大致有JSONP,反向代理,CORS这三种方式.JSONP兼容性良好,最大的缺点是只支持 ...
- Windows下Nginx配置SSL实现Https访问(包含证书生成)
Vincent.李 Windows下Nginx配置SSL实现Https访问(包含证书生成) Windows下Nginx配置SSL实现Https访问(包含证书生成) 首先要说明为什么要实现https ...
- Nginx 配置简述
不论是本地开发,还是远程到 Server 开发,还是给提供 demo 给人看效果,我们时常需要对 Nginx 做配置,Nginx 的配置项相当多,如果考虑性能配置起来会比较麻烦.不过,我们往往只是需要 ...
- Nginx配置详解
序言 Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的.从2004年发布至今,凭借开源的力量,已经接近成熟与完善. Nginx功能丰富,可作为HTTP服务器,也 ...
- Nginx配置Https
1.申请证书: https://console.qcloud.com/ssl?utm_source=yingyongbao&utm_medium=ssl&utm_campaign=qc ...
- nginx配置为windows服务中的坑
网上搜索“nginx 配置为windows服务”,很容易搜索到使用windows server warpper来配置,于是按照网上的方法我从github上的链接下载了1.17版本,前面都很顺利,很容易 ...
- 【nginx配置】nginx做非80端口转发
一个场景 最近在使用PHP重写一个使用JAVA写的项目,因为需要查看之前的项目,所以要在本地搭建一个Tomcat来跑JAVA的项目.搭建成功后,因为Tomcat监听的端口是8080,因此,访问的URL ...
随机推荐
- vuex其实超简单,只需3步
前言 之前几个项目中,都多多少少碰到一些组件之间需要通信的地方,而因为种种原因,event bus 的成本反而比vuex还高, 所以技术选型上选用了 vuex, 但是不知道为什么,团队里的一些新人一听 ...
- 三段式fsm
1.状态转移的always中CS,同步ouput的always中NS. 2.3段fsm vs 2段fsm:output逻辑是组合逻辑和同步时序逻辑(消除里不稳的和毛刺). 3.3段fsm vs 1段f ...
- linux终端颜色控制
引言: 由于在c代码中看到过打印彩色字, 又对PS1 想进一步了解,才有了这篇博文.----------------------------------------Linux 终端控制台字体颜色 - ...
- js实现一个简单的响应式双向数据绑定
一,基本原理 我们这里使用了对象中的一个特殊属性:访问器属性,这个属性不能在对象中设置,而是必须通过defineProperty()方法单独定义. 我们首先定义一个函数: var obj = { }; ...
- 关于requirejs和grunt压缩合并是否矛盾
requirejs主要是为了模块化开发,这样带来的好处不言而喻.但是分成多个js文件增加了请求数,那么就要用到合并压缩.合并压缩了原来的许多独立的js模块,那requirejs又是怎么冲压缩的文件中找 ...
- Leetcode 377.组合总和IV
组合总和IV 给定一个由正整数组成且不存在重复数字的数组,找出和为给定目标正整数的组合的个数. 示例: nums = [1, 2, 3] target = 4 所有可能的组合为: (1, 1, 1, ...
- Android自制rom,为update.zip签名
确认已经安装好openssl openssl genrsa -out key.pem openssl req -new -key key.pem -out request.pem openssl x5 ...
- 洛谷P3097 - [USACO13DEC]最优挤奶Optimal Milking
Portal Description 给出一个\(n(n\leq4\times10^4)\)个数的数列\(\{a_n\}(a_i\geq1)\).一个数列的最大贡献定义为其中若干个不相邻的数的和的最大 ...
- COdevs 天梯 水题系列
1203 判断浮点数是否相等 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题目描述 Description 给出两个浮点数,请你判断这两个浮点数是否相等 输入 ...
- set_include_path() &&get_include_path()用法
function initialize(){ set_include_path(get_include_path().PATH_SEPARATOR . "core/"); ...