Nginx主配置参数详解,Nginx配置网站

时间:2022-08-31 10:16:14

1.Niginx主配置文件参数详解

  a.上面博客说了在Linux中安装nginx。博文地址为:http://www.cnblogs.com/hanyinglong/p/5102141.html

  b.当Nginx安装完毕后,会有相应的安装目录,安装目录里的nginx.confg为nginx的主配置文件,nginx主配置文件分为4部分,main(全局配置)、server(主机配置)、upstream(负载均衡服务器设置)以及location(URL匹配特定位置的设置),这四者的关系是:server继承main,location继承server,upstream既不会继承其它设置也不会被继承。

  c.Nginx是一个代理服务器,一般情况下,网站是不能部署在Nginx下的,比如用Java开发的JavaWeb程序,我们部署在tomcat下,然后使用Nginx代理将网址指向tomcat即可。

2.Nginx.conf配置文件详细说明(附备注)

 #  kencery 注释说明Nginx文件
# 时间:2016-1-19
# 学习内容,只是来自互联网,有版权问题请联系我删除。 ######## Nginx的main(全局配置)文件
#指定nginx运行的用户及用户组,默认为nobody
#user nobody; #开启的线程数,一般跟逻辑CPU核数一致
worker_processes 1; #定位全局错误日志文件,级别以notice显示,还有debug,info,warn,error,crit模式,debug输出最多,crir输出最少,根据实际环境而定
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #指定进程id的存储文件位置
#pid logs/nginx.pid; #指定一个nginx进程打开的最多文件描述符数目,受系统进程的最大打开文件数量限制
#worker_rlimit_nofile 65535 events {
#设置工作模式为epoll,除此之外还有select,poll,kqueue,rtsig和/dev/poll模式
#use epoll; #定义每个进程的最大连接数,受系统进程的最大打开文件数量限制。
worker_connections 1024;
} #######Nginx的Http服务器配置,Gzip配置
http {
#主模块指令,实现对配置文件所包含的文件的设定,可以减少主配置文件的复杂度,DNS主配置文件中的zonerfc1912,acl基本上都是用include语句。
include mime.types; #核心模块指令,智力默认设置为二进制流,也就是当文件类型未定义时使用这种方式
default_type application/octet-stream; #下面代码为日志格式的设定,main为日志格式的名称,可自行设置,后面引用
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #引用日志main
#access_log logs/access.log main; #设置允许客户端请求的最大的单个文件字节数
#client_max_body_size 20M;
#指定来自客户端请求头的headebuffer大小
#client_header_buffer_size 32k;
#指定连接请求试图写入缓存文件的目录路径
#client_body_temp_path /dev/shm/client_body_temp;
#指定客户端请求中较大的消息头的缓存最大数量和大小,目前设置为4个32KB
#large client_header_buffers 4 32k; #开启高效文件传输模式
sendfile on;
#开启防止网络阻塞
#tcp_nopush on;
#开启防止网络阻塞
#tcp_nodelay on; #设置客户端连接保存活动的超时时间
#keepalive_timeout 0;
keepalive_timeout 65; #设置客户端请求读取超时时间
#client_header_timeout 10;
#设置客户端请求主体读取超时时间
#client_body_timeout 10;
#用于设置相应客户端的超时时间
#send_timeout ####HttpGZip模块配置
#httpGzip modules
#开启gzip压缩
#gzip on;
#设置允许压缩的页面最小字节数
#gzip_min_length 1k;
#申请4个单位为16K的内存作为压缩结果流缓存
#gzip_buffers 4 16k;
#设置识别http协议的版本,默认为1.1
#gzip_http_version 1.1;
#指定gzip压缩比,1-9数字越小,压缩比越小,速度越快
#gzip_comp_level 2;
#指定压缩的类型
#gzip_types text/plain application/x-javascript text/css application/xml;
#让前端的缓存服务器进过gzip压缩的页面
#gzip_vary on; #########Nginx的server虚拟主机配置
server {
#监听端口为 80
listen 80; #设置主机域名
server_name localhost; #设置访问的语言编码
#charset koi8-r; #设置虚拟主机访问日志的存放路径及日志的格式为main
#access_log logs/host.access.log main; #设置虚拟主机的基本信息
location / {
#设置虚拟主机的网站根目录
root 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 html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }

3.Nginx代理网站

  a.我在tomcat下部署了一个javaweb项目,tomcat安装的服务器IP为:192.168.37.136,部署的项目在tomcat下的访问地址为:http://192.168.37.136:8080/lywh/

  b.我在IP为192.168.37.133的服务器下面安装成功了Nginx。

  c.那怎么样将tomcat下部署的网站使用Nginx代理呢?,修改Nginx的配置文件,修改命令:vim /usr/local/nginx/conf/nginx.conf

 #user  nobody;
worker_processes ;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections ;
}
http {
include 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 logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on; #配置tomcat的IP地址和访问端口
upstream gw {
server 192.168.37.136: weight=;
}
server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
}
#Nginx代理配置
location /lywh {
proxy_pass http://gw/lywh;
}
location /sapi {
proxy_pass http://gw/shopappapi;
}
location /cas{
proxy_pass http://gw/cas-server-webapp-4.0.0/login;
}
location /doc{
proxy_pass http://gw/docs;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }

  d.当配置完Nginx.conf之后,关闭文件,执行命令检查配置的文件是否有问题,如果如图所示则说明没有问题,否则需要检查配置是否出现问题

    Nginx主配置参数详解,Nginx配置网站

  e.检查如果返回ok,则说明修改文件没有出现任何错误,这时候重启Nginx,命令为: /usr/local/nginx/sbin/nginx -s reload

  f.最后访问代理后的网站,http://192.168.37.133/lywh,如图所示:则说明已经代理访问:

    Nginx主配置参数详解,Nginx配置网站

    这篇笔记已写完,如果大家有什么疑问可以和我探讨,我也是一边学习一边写的笔记,如哪里有错误之处,请告知

          最后祝愿大家新年快乐,明天回家,旅途顺利

Nginx主配置参数详解,Nginx配置网站的更多相关文章

  1. Nginx 主配置文件参数详解

    Nginx 主配置文件参数详解 Nginx 安装完毕后,会有响应的安装目录,安装目录里 nginx.conf 为 nginx 的主配置文件, ginx 主配置文件分为 4 部分,main(全局配置). ...

  2. nginx配置参数详解

    配置参数详解 user nginx nginx ; Nginx用户及组:用户 组.window下不指定 worker_processes 8; 工作进程:数目.根据硬件调整,通常等于CPU数量或者2倍 ...

  3. nginx的gzip模块详解以及配置

    文章来源 运维公会:nginx的gzip模块详解以及配置   1.gzip模块作用 gzip这个模块无论在测试环境还是生产环境都是必须要开启,这个模块能高效的将页面的内容,无论是html或者css.j ...

  4. mha配置参数详解

    mha配置参数详解: 参数名字 是否必须 参数作用域 默认值 示例 hostname Yes Local Only - hostname=mysql_server1, hostname=192.168 ...

  5. Redis配置参数详解

    Redis配置参数详解 /********************************* GENERAL *********************************/ // 是否作为守护进 ...

  6. MHA配置参数详解 【转】

    mha配置参数详解: 参数名字 是否必须 参数作用域 默认值 示例 hostname Yes Local Only - hostname=mysql_server1, hostname=192.168 ...

  7. zookeeper的配置参数详解(zoo.cfg)

    配置参数详解(主要是%ZOOKEEPER_HOME%/conf/zoo.cfg文件) 参数名 说明 clientPort 客户端连接server的端口,即对外服务端口,一般设置为2181吧. data ...

  8. rsync的介绍及参数详解,配置步骤,工作模式介绍

    rsync的介绍及参数详解,配置步骤,工作模式介绍 rsync是类unix系统下的数据镜像备份工具.它是快速增量备份.全量备份工具. Sync可以远程同步,支持本地复制,或者与其他SSH.rsync主 ...

  9. samba 配置参数详解

    samba 配置参数详解: 一.全局配置参数  workgroup = WORKGROUP说明:设定 Samba Server 所要加入的工作组或者域. server string = Samba S ...

随机推荐

  1. Daily Scrum Meeting ——FirstDay

    一.Daily Scrum Meeting照片 二.Burndown Chart 三.项目进展 1.介绍在github上发布的issues 根据MVC三层模型,我们主要发布的是V层以及M层,C层将根据 ...

  2. vim的批量注释与删除注释

    vim的批量注释与删除注释 方法一:块选择模式 批量注释: Ctrl + v 进入块选择模式,然后移动光标选中你要注释的行,再按大写的I进入行首插入模式输入注释符号如 // 或 #,输入完毕之后,Vi ...

  3. Whitespace character

    In computer science, whitespace is any character or series of whitespace characters that represent h ...

  4. phoneGap开发环境搭建(android)

    1.  首先安装nodejs  (http://nodejs.org/) 2.  然后在命令行输入 npm 回车 假设出现下图: 则表示成功安装 3. 安装 npm install -g cordov ...

  5. Java 控制台输入数字 输出乘法表(代码练习)

    最近,回忆了一些刚学习Java时经常练习的一些小练习题.感觉还是蛮有趣的,在回顾时想起好多学习时的经历和坎坷,一道小小的练习题要研究半天,珍重过往,直面未来.下面贡献代码,Java 控制台输入数字 输 ...

  6. web service简述,通俗易懂----转

    一.Web Service简介 1.1.Web Service基本概念 Web Service也叫XML Web Service WebService是一种可以接收从Internet或者Intrane ...

  7. Java线程创建的两种方式

    java多线程总结一:线程的两种创建方式及优劣比较 (一)---之创建线程的两种方式 java实现多线程的两种方法的比较

  8. spring websocket集群问题的简单记录

    目录 前言 解决方案 代码示例 前言 最近公司里遇到一个问题,在集群中一些websocket的消息丢失了. 产生问题的原理很简单,发送消息的服务和接收者连接的服务不是同一个服务. 解决方案 用中间件( ...

  9. poj 2079(旋转卡壳求解凸包内最大三角形面积)

    Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 9060   Accepted: 2698 Descript ...

  10. Pinball Save Earth 正式上线

    有问题或者建议大家可以联系我的QQ 914287516 或者qq邮箱 官方qq群 325631077: