关于Nginx的基础理解,淘宝的文档已经介绍很清楚了:http://tengine.taobao.org/book/
以下记录些具体的使用流程,方便日后查看。
一. 整体配置步骤:
- 安装Nginx。
- 安装依赖包,包括 pcre 以及 zlib 依赖。centos7的 root 权限下 yum list 搜索,再安装。
- 下载Nginx。./configure ---> make ---> make install.(安装成功看提示就知道安装在哪,一般在/usr/local/nginx)
- 访问 wget 127.0.0.1 即可看到安装成功。
- 准备一个机子放Web应用,例如我的应用地址为 192.168.1.99.157:8081/springmvc。再准备一个机子(我的安装Nginx的机子的IP为192.168.199.176)安装上述的Nginx(其实你用同一个机子也是可以测试的,用不同的 端口当做不同的机子)
- 在安装了Nginx的机子上修改nginx.conf主配置文件。例如如下的配置文件(测试版):
<preLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word; background-color:rgb(247,247,249); padding:10px; border:1px solid rgb(225,225,232)">
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">worker_processes 2;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">events {
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> worker_connections 1024;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">}
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">http {
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> server_tokens off;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> include mime.types;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> default_type application/octet-stream;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> charset utf-8;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> server_names_hash_bucket_size 128;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> client_header_buffer_size 32k;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> large_client_header_buffers 4 32k;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> client_max_body_size 300m;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> tcp_nopush on;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> tcp_nodelay on;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> client_body_buffer_size 512k;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> proxy_connect_timeout 300s;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> proxy_read_timeout 300s;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> proxy_send_timeout 300s;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> proxy_buffer_size 64k;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> proxy_buffers 4 32k;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> proxy_busy_buffers_size 64k;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> proxy_temp_file_write_size 128k;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> proxy_ignore_client_abort on;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> gzip on;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> gzip_http_version 1.1;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> gzip_min_length 1k;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> gzip_buffers 4 16k;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> gzip_types text/plain application/x-javascript text/css application/xml;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> gzip_comp_level 2;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> gzip_vary on;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> log_format main '$remote_addr - $remote_user [$time_local] "$request" '
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> '$status $body_bytes_sent "$http_referer" '
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> '"$http_user_agent" "$http_x_forwarded_for"';
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> upstream apm {
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> server 192.168.199.157:8081;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> }
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> server {
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> listen 8080;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> server_name 192.168.199.176;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> charset utf-8;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> location /springmvc/ {
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> proxy_pass http://apm;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> }
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> }
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> sendfile on;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word"> keepalive_timeout 65;
<codeLiberation Mono',Menlo,Courier,monospace; word-wrap:break-word">}
- 访问 192.168.199.176:8080/springmvc/ 时,成功访问到 192.168.199.157:8081/springmvc 的首页
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了Nginx 反向代理 Demo,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!