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 ...
随机推荐
- element使用心得
Table Table 常用属性解释 数据过滤,filter过滤器 <el-table-column width="200" show-overflow-tooltip la ...
- Linux文件权限基础(一)
Linux中每个文件或者目录对都有一组共9个基础权限位,没三位字符被分为一组,他们分别是属主权限位,用户组权限位,其他用户权限位. 示例: 权限位说明: r --read 可读权限 对应数字4 w - ...
- python爬虫入门六:Selenium库
在我们爬取网页过程中,经常发现我们想要获得的数据并不能简单的通过解析HTML代码获取,这些数据是通过AJAX异步加载方式或经过JS渲染后才呈现在页面上显示出来. selenuim是一种自动化测试工具, ...
- map函数的应用:UVa156-Ananagrams
Ananagrams Most crossword puzzle fans are used to anagrams - groups of words with the same letters i ...
- python基础学习笔记——初识函数
什么是函数 我们目前为止,已经可以完成一些软件的基本功能了,那么我们来完成这样一个功能:约x 1 2 3 4 5 pint("拿出手机") print("打开陌陌&quo ...
- Knockout v3.4.0 中文版教程-4-通过监控数组工作
2.通过监控数组工作 1. 监控数组 如果你想检测或者响应一个对象的改变,你用observables.如果你想检测和响应一个集合的改变,使用observableArray.这个在很多情况下都非常有用, ...
- Pyhton开发:Python基础杂货铺
if 语句 Python条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行的代码块. Python中if语句的一般形式如下所示: if condition_1: stateme ...
- 转:深入 AngularUI Router
原文地址:http://www.ng-newsletter.com/posts/angular-ui-router.html ui-router: https://angular-ui.github. ...
- php官方微信接口大全
微信入口绑定,微信事件处理,微信API全部操作包含在这些文件中.内容有:微信摇一摇接口/微信多客服接口/微信支付接口/微信红包接口/微信卡券接口/微信小店接口/JSAPI <?php class ...
- Leetcode 385.字典序排序
字典序排序 给定一个整数 n, 返回从 1 到 n 的字典顺序. 例如, 给定 n =1 3,返回 [1,10,11,12,13,2,3,4,5,6,7,8,9] . 请尽可能的优化算法的时间复杂度和 ...