Linux下部署配置Nginx
1、安装工具包
yum install -y wget 下载工具
yum install -y vim-enhanced vim编辑器
yum install -y make cmake gcc gcc-c++ 编译源代码
2、安装依赖包
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
3、下载地址:http://nginx.org/download
# wget http://nginx.org/download/×××
4、解压压缩包之后进行configure配置
# ./configure --perfix=/usr/local/nginx
5、编译安装
make install
6、启动nginx:# /usr/local/nginx/sbin/nginx
关闭nginx:#/usr/local/nginx/sbin/nginx -s stop
重启nginx:#/usr/local/nginx/sbin/nginx -s reload
7、开启防火墙80端口
firewall -cmd --zone=publice -- add-port=80/tcp -- permanent
firewall -cmd --reload
8、检查nginx安装成功
ps aux|grep nginx
网页输入ip查看结果
9、nginx配置 # vi /usr/local/nginx/conf/nginx.con
以下为需要配置的代码段
server {
listen 80; #监听端口
server_name localhost; #监听域名
#上传文件通常需要设置nginx报文大小限制;避免出现413 请求实体太大
client_max_body_size 1024M;
# 如果没有location更明确的匹配访问路径的话,访问请求都会被该location处理。
location / {
#root指定nginx的根目录为/usr/local/nginx/html
root html;
# 默认访问文件,欢迎页先去html目录下找index.html,如果找不到再去找index.htm
index index.html index.htm;}
10、nginx的主要用途
[1]反向代理
反向代理(Reverse Proxy)方式是指以代理服务器来接受 internet上 的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给 internet 上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。
server {
listen 80;
server_name localhost;
location /gcisp-web/ {
proxy_pass http://10.153.130.47:5050/gcisp/;
proxy_connect_timeout 75s;
}
location /gcisp/ {
proxy_pass http://10.148.16.95:8080/gcisp/;
proxy_connect_timeout 5s;
#proxy_read_timeout 20s;}}
or
location / {
root html;
index index.html index.htm;}
location /tssp-map/ {
alias /usr/local/linkcm/dist/;}
location /tssp-warn/ {
proxy_pass http://192.168.2.41:8083/tssp-warn/;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}
[2] 负载均衡
负载均衡也是 Nginx 常用的一个功能,负载均衡其意思就是分摊到多个操作单元上进行执行。
(1)每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
upstream server {
ip_hash;
server localhost:8080;
server localhost:8081;}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://test;
proxy_set_header Host $host:$server_port;}}
(2)fair(第三方)
按后端服务器的响应时间来分配请求,响应时间短的优先分配。
upstream server{
server localhost:8080;
server localhost:8081;
fair;}
[3]文件映射
映射服务器的文件资源
server {
listen 81;
server_name localhost;
location /contract/{
alias /home/gcisp/contract/;
expires 10d;
autoindex on;
index index.html index.htm;}}
[4]HTTP服务器
Nginx也是一个静态资源的服务器,当只有静态资源的时候,就可以使用Nginx来做服务器,同时也可以动静分离。
(1) 静态资源
server {
listen 80;
server_name localhost;
location / {
root c:\root;
index index.html;}}
# 访问到c盘root目录下面的index.html
(2) 动静分离
动静分离是让动态网站里的动态网页根据一定规则把不变的资源和经常变的资源区分开来,动静资源做好了拆分以后,我们就可以根据静态资源的特点将其做缓存操作。
upstream server{
server localhost:8080;
server localhost:8081; }
server {
listen 80;
server_name localhost;
location / {
root c:\root;
index index.html; }
# 所有静态请求都由nginx处理,存放目录为html
location ~ \.(gif|jpg|jpeg|png|bmp|swf|css|js)$ {
root c:\root;
}
# 所有动态请求都转发给tomcat处理
location ~ \.(jsp|do)$ {
proxy_pass http://test;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root c:\root; }}
[5] 正向代理
一个位于客户端和原始服务器(origin server)之间的服务器,为了从原始服务器取得内容,客户端向代理发送一个请求并指定目标(原始服务器),然后代理向原始服务器转交请求并将获得的内容返回给客户端。resolver是配置正向代理的DNS服务器,listen 是正向代理的端口
resolver 114.114.114.114 8.8.8.8;
server {
resolver_timeout 5s;
listen 80;
location / {
proxy_pass http://$host$request_uri;}}
11、nginx配置响应时间(常用)
proxy_connect_timeout 75s; 链接
proxy_read_timeout 75s; 读取
proxy_send_timeout 75s; 发请求
12、附录nginx.conf详细配置:https://blog.csdn.net/tjcyjd/article/details/50695922
Linux下部署配置Nginx的更多相关文章
- Linux 下安装配置nginx及常见问题解答
其实也不能完全算是原创吧!都是我配置nginx时所遇到的问题,查阅资料后总结起来.即是巩固一下nginx的配置,也是分享给新入Linux的童鞋们一些知识 好了,不多废话,进入主题吧! 为nginx添加 ...
- linux 下安装配置jboss as7以及部署应用
linux 下安装配置jboss as7以及部署应用 1.测试平台及软件 centos 5.4 jdk-7u5-linux-i586.rpm jboss-as-7.1.1.Final.zip jbos ...
- [亲测]ASP.NET Core 2.0怎么发布/部署到Ubuntu Linux服务器并配置Nginx反向代理实现域名访问
前言 ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用ASP.NET Core网站绑定到指定的域名,让外网用户可以访问呢? 步骤 第1步:准备工作 一台Liun ...
- [亲测]七步学会ASP.NET Core 2.0怎么发布/部署到Ubuntu Linux服务器并配置Nginx反向代理实现域名访问
前言 ASP.NET Core 2.0 怎么发布到Ubuntu服务器?又如何在服务器上配置使用ASP.NET Core网站绑定到指定的域名,让外网用户可以访问呢? 步骤 第1步:准备工作 一台Liun ...
- (转)windows 下安装配置 Nginx 详解
windows 下安装配置 Nginx 详解 本文转自https://blog.csdn.net/kingscoming/article/details/79042874 nginx功能之一可以启动一 ...
- Linux 下部署Django项目
Linux 下部署Django项目 说明:本文所使用的环境为CentOS 6+Python2.7+Django1.11 安装Django.Nginx和uWSGI 1.确定已经安装了2.7版本的Py ...
- linux 下部署nodejs(两种方式)
本次博客的编写时用的系统环境,刚装好的Centos 6.4 64位虚拟机. 另外关于linux 其他系统的安装 可以参考https://github.com/joyent/node/wiki/Ins ...
- Linux下部署Symfony2对app/cache和app/logs目录的权限设置
在linux下部署完Symfony2,可能在访问的时候会报app/logs或者app/cache目录没有写权限的错误.在linux下,如果我们在命令行登陆的用户和web应用服务器(apache.ngi ...
- LNMP1.3一键安装Linux环境,配置Nginx运行ThinkPHP3.2
LNMP1.3一键安装Linux环境,配置Nginx运行ThinkPHP3.2 你是否遇见过:安装LNMP1.3环境后,运行ThinkPHP 3.2,只能打开首页,不能访问控制器,报404错误. 按照 ...
随机推荐
- 使用webpack && react环境
使用webpack webpack是一款模块化的打包工具,它认为所有的文件都是模块,包括js,css等等,版本为2.x推荐学习,1.x版本已废弃,不建议使用. 目前,facebook官方就是使用web ...
- C#集合通论
前言 写这篇文章的最初动力是来自于一次笔试经历.有一道笔试题大概是这样的:程序使用一个txt文件来存储操作记录.存储记录是多行字符串,每一行代表一次操作记录,格式如下:用户名+操作事项名称+操作时间. ...
- 【Maven学习】maven中依赖的配置详解
根元素project下的dependencies可以包含一个或者多个dependency元素,以声明一个或多个项目依赖.每个依赖可以包含的元素有: groupId,artifactId和version ...
- hibernate多对一单向关联注解方式
多对一单向关联,在多的一方加上一的一方作为外键.在程序里表现为:在多的一方加上一的引用. 小组类Group,用户User: Group: package com.oracle.hibernate; i ...
- Scope of a Declaration
6.3. Scope of a Declaration The scope of a declaration of a member m declared in or inherited by an ...
- JavaScript设计模式-9.工厂模式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Linux常用命令之sed(2)
Sed SED的英文全称是 Stream EDitor,它是一个简单而强大的文本解析转换工具,在1973-1974年期间由贝尔实验室的Lee E. McMahon开发,今天,它已经运行在所有的主流操作 ...
- 认识HDFS分布式文件系统
1.设计基础目标 (1) 错误是常态,需要使用数据冗余 (2)流式数据访问.数据批量读而不是随机速写,不支持OLTP,hadoop擅长数据分析而不是事物处理. (3)文件采用一次性写多次读的模型, ...
- jQueryEasyUI 学习笔记
jQuery EasyUI是什么? jQuery EasyUI是一组基于jQuery的UI插件集合体,而jQuery EasyUI的目标就是帮助web开发者更轻松的打造出功能丰富并且美观的UI界面.开 ...
- Implicit super constructor xx() is undefined for default constructor. Must define an explicit constructor
错误:Implicit super constructor xx() is undefined for default constructor. Must define an explicit c ...