如何在 FreeBSD 10.2 上安装 Nginx 作为 Apache 的反向代理
Nginx 是一款自由开源的 HTTP 和反向代理服务器,也可以用作 POP3/IMAP 的邮件代理服务器。Nginx 是一款高性能的 web 服务器,其特点是功能丰富,结构简单以及内存占用低。 第一个版本由 Igor Sysoev 发布于2002年,到现在有很多大型科技公司在使用,包括 Netflix、 Github、 Cloudflare、 WordPress.com 等等。
在这篇教程里我们会“在 FreeBSD 10.2 系统上,安装和配置 Nginx 网络服务器作为 Apache 的反向代理”。 Apache 将在8080端口上运行 PHP ,而我们会配置 Nginx 运行在80端口以接收用户/访问者的请求。如果80端口接收到用户浏览器的网页请求,那么 Nginx 会将该请求传递给运行在8080端口上的 Apache 网络服务器和 PHP。
前提条件
- FreeBSD 10.2
- Root 权限
步骤 1 - 更新系统
使用 SSH 认证方式登录到你的 FreeBSD 服务器,使用下面命令来更新你的系统:
<span class="pln">freebsd</span><span class="pun">-</span><span class="pln">update fetch</span>
<span class="pln">freebsd</span><span class="pun">-</span><span class="pln">update install</span>
步骤 2 - 安装 Apache
Apache 是开源的、使用范围最广的 web 服务器。在 FreeBSD 里默认没有安装 Apache, 但是我们可以直接通过 /usr/ports/www/apache24 下的 ports 或软件包来安装,也可以直接使用 pkg 命令从 FreeBSD 软件库中安装。在本教程中,我们将使用 pkg 命令从 FreeBSD 软件库中安装:
<span class="pln">pkg install apache24</span>
步骤 3 - 安装 PHP
一旦成功安装 Apache,接着将会安装 PHP ,它来负责处理用户对 PHP 文件的请求。我们将会用到如下的 pkg 命令来安装 PHP:
<span class="pln">pkg install php56 mod_php56 php56</span><span class="pun">-</span><span class="pln">mysql php56</span><span class="pun">-</span><span class="pln">mysqli</span>
步骤 4 - 配置 Apache 和 PHP
一旦所有都安装好了,我们将会配置 Apache 运行在8080端口上, 并让 PHP 与 Apache 一同工作。 要想配置Apache,我们可以编辑“httpd.conf”这个配置文件, 对于 PHP 我们只需要复制 “/usr/local/etc/”目录下的 PHP 配置文件 php.ini。
进入到“/usr/local/etc/”目录,并且复制 php.ini-production 文件到 php.ini :
<span class="kwd">cd</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span>
<span class="kwd">cp</span><span class="pln"> php</span><span class="pun">.</span><span class="pln">ini</span><span class="pun">-</span><span class="pln">production php</span><span class="pun">.</span><span class="pln">ini</span>
下一步,在 Apache 目录下通过编辑“httpd.conf”文件来配置 Apache:
<span class="kwd">cd</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">apache24</span>
<span class="kwd">nano</span><span class="pun">-</span><span class="pln">c httpd</span><span class="pun">.</span><span class="pln">conf</span>
端口配置在第52行 :
<span class="typ">Listen</span><span class="lit">8080</span>
服务器名称配置在第219行:
<span class="typ">ServerName</span><span class="lit">127.0</span><span class="pun">.</span><span class="lit">0.1</span><span class="pun">:</span><span class="lit">8080</span>
在第277行,添加 DirectoryIndex 文件,Apache 将用它来服务对目录的请求:
<span class="typ">DirectoryIndex</span><span class="pln"> index</span><span class="pun">.</span><span class="pln">php index</span><span class="pun">.</span><span class="pln">html</span>
在第287行下,配置 Apache ,添加脚本支持:
<span class="tag"><FilesMatch</span><span class="atv">"\.php$"</span><span class="tag">></span>
<span class="pln">SetHandler application/x-httpd-php</span>
<span class="tag"></FilesMatch></span>
<span class="tag"><FilesMatch</span><span class="atv">"\.phps$"</span><span class="tag">></span>
<span class="pln">SetHandler application/x-httpd-php-source</span>
<span class="tag"></FilesMatch></span>
保存并退出。
现在用 sysrc 命令,来添加 Apache 为开机启动项目:
<span class="pln">sysrc apache24_enable</span><span class="pun">=</span><span class="kwd">yes</span>
然后用下面的命令测试 Apache 的配置:
<span class="pln">apachectl configtest</span>
如果到这里都没有问题的话,那么就启动 Apache 吧:
<span class="pln">service apache24 start</span>
如果全部完毕,在“/usr/local/www/apache24/data”目录下创建一个 phpinfo 文件来验证 PHP 在 Apache 下顺利运行:
<span class="kwd">cd</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">apache24</span><span class="pun">/</span><span class="pln">data</span>
<span class="kwd">echo</span><span class="str">"<?php phpinfo(); ?>"</span><span class="pun">></span><span class="kwd">info</span><span class="pun">.</span><span class="pln">php</span>
现在就可以访问 freebsd 的服务器 IP : 192.168.1.123:8080/info.php 。
Apache and PHP on Port 8080
Apache 及 PHP 运行在 8080 端口。
步骤 5 - 安装 Nginx
Nginx 可以以较低内存占用提供高性能的 Web 服务器和反向代理服务器。在这个步骤里,我们将会使用 Nginx 作为Apache 的反向代理,因此让我们用 pkg 命令来安装它吧:
<span class="pln">pkg install nginx</span>
步骤 6 - 配置 Nginx
一旦 Nginx 安装完毕,在“nginx.conf”文件里,我们需要做一个新的配置文件来替换掉原来的 nginx 配置文件。切换到“/usr/local/etc/nginx/”目录下,并且备份默认 nginx.conf 文件:
<span class="kwd">cd</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span>
<span class="kwd">mv</span><span class="pln"> nginx</span><span class="pun">.</span><span class="pln">conf nginx</span><span class="pun">.</span><span class="pln">conf</span><span class="pun">.</span><span class="pln">oroginal</span>
现在就可以创建一个新的 nginx 配置文件了:
<span class="kwd">nano</span><span class="pun">-</span><span class="pln">c nginx</span><span class="pun">.</span><span class="pln">conf</span>
然后粘贴下面的配置:
<span class="pln">user www</span><span class="pun">;</span>
<span class="pln">worker_processes </span><span class="lit">1</span><span class="pun">;</span>
<span class="pln">error_log </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">error</span><span class="pun">.</span><span class="pln">log</span><span class="pun">;</span>
<span class="pln">events </span><span class="pun">{</span>
<span class="pln">worker_connections </span><span class="lit">1024</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="pln">http </span><span class="pun">{</span>
<span class="kwd">include</span><span class="pln"> mime</span><span class="pun">.</span><span class="pln">types</span><span class="pun">;</span>
<span class="pln">default_type application</span><span class="pun">/</span><span class="pln">octet</span><span class="pun">-</span><span class="pln">stream</span><span class="pun">;</span>
<span class="pln">log_format main </span><span class="str">'$remote_addr - $remote_user [$time_local] "$request" '</span>
<span class="str">'$status $body_bytes_sent "$http_referer" '</span>
<span class="str">'"$http_user_agent" "$http_x_forwarded_for"'</span><span class="pun">;</span>
<span class="pln">access_log </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">access</span><span class="pun">.</span><span class="pln">log</span><span class="pun">;</span>
<span class="pln">sendfile on</span><span class="pun">;</span>
<span class="pln">keepalive_timeout </span><span class="lit">65</span><span class="pun">;</span>
<span class="com">#</span><span class="typ">Nginx</span><span class="pln"> cache configuration</span>
<span class="pln">proxy_cache_path </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">cache levels</span><span class="pun">=</span><span class="lit">1</span><span class="pun">:</span><span class="lit">2</span><span class="pln"> keys_zone</span><span class="pun">=</span><span class="kwd">my</span><span class="pun">-</span><span class="pln">cache</span><span class="pun">:</span><span class="lit">8m</span><span class="pln"> max_size</span><span class="pun">=</span><span class="lit">1000m</span><span class="pln"> inactive</span><span class="pun">=</span><span class="lit">600m</span><span class="pun">;</span>
<span class="pln">proxy_temp_path </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">cache</span><span class="pun">/</span><span class="pln">tmp</span><span class="pun">;</span>
<span class="pln">proxy_cache_key </span><span class="str">"$scheme$host$request_uri"</span><span class="pun">;</span>
<span class="pln">gzip on</span><span class="pun">;</span>
<span class="pln">server </span><span class="pun">{</span>
<span class="com">#</span><span class="pln">listen </span><span class="lit">80</span><span class="pun">;</span>
<span class="pln">server_name _</span><span class="pun">;</span>
<span class="pln">location </span><span class="pun">/</span><span class="pln">nginx_status </span><span class="pun">{</span>
<span class="pln">stub_status on</span><span class="pun">;</span>
<span class="pln">access_log off</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="com">#</span><span class="pln"> redirect server error pages to the </span><span class="kwd">static</span><span class="pln"> page </span><span class="pun">/</span><span class="lit">50x</span><span class="pun">.</span><span class="pln">html</span>
<span class="com">#</span>
<span class="pln">error_page </span><span class="lit">500</span><span class="lit">502</span><span class="lit">503</span><span class="lit">504</span><span class="pun">/</span><span class="lit">50x</span><span class="pun">.</span><span class="pln">html</span><span class="pun">;</span>
<span class="pln">location </span><span class="pun">=</span><span class="pun">/</span><span class="lit">50x</span><span class="pun">.</span><span class="pln">html </span><span class="pun">{</span>
<span class="pln">root </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">-</span><span class="pln">dist</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="com">#</span><span class="pln"> proxy the PHP scripts to </span><span class="typ">Apache</span><span class="pln"> listening on </span><span class="lit">127.0</span><span class="pun">.</span><span class="lit">0.1</span><span class="pun">:</span><span class="lit">8080</span>
<span class="com">#</span>
<span class="pln">location </span><span class="pun">~</span><span class="pln"> \.php$ </span><span class="pun">{</span>
<span class="pln">proxy_pass http</span><span class="pun">:</span><span class="com">//127.0.0.1:8080;</span>
<span class="kwd">include</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">proxy</span><span class="pun">.</span><span class="pln">conf</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="pun">}</span>
<span class="kwd">include</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">vhost</span><span class="com">/*;</span>
<span class="com">}</span>
保存并退出。
下一步,在 nginx 目录下面,创建一个 proxy.conf 文件,使其作为反向代理 :
<span class="kwd">cd</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span>
<span class="kwd">nano</span><span class="pun">-</span><span class="pln">c proxy</span><span class="pun">.</span><span class="pln">conf</span>
粘贴如下配置:
<span class="pln">proxy_buffering on</span><span class="pun">;</span>
<span class="pln">proxy_redirect off</span><span class="pun">;</span>
<span class="pln">proxy_set_header </span><span class="typ">Host</span><span class="pln"> $host</span><span class="pun">;</span>
<span class="pln">proxy_set_header X</span><span class="pun">-</span><span class="typ">Real</span><span class="pun">-</span><span class="pln">IP $remote_addr</span><span class="pun">;</span>
<span class="pln">proxy_set_header X</span><span class="pun">-</span><span class="typ">Forwarded</span><span class="pun">-</span><span class="typ">For</span><span class="pln"> $proxy_add_x_forwarded_for</span><span class="pun">;</span>
<span class="pln">client_max_body_size </span><span class="lit">10m</span><span class="pun">;</span>
<span class="pln">client_body_buffer_size </span><span class="lit">128k</span><span class="pun">;</span>
<span class="pln">proxy_connect_timeout </span><span class="lit">90</span><span class="pun">;</span>
<span class="pln">proxy_send_timeout </span><span class="lit">90</span><span class="pun">;</span>
<span class="pln">proxy_read_timeout </span><span class="lit">90</span><span class="pun">;</span>
<span class="pln">proxy_buffers </span><span class="lit">100</span><span class="lit">8k</span><span class="pun">;</span>
<span class="pln">add_header X</span><span class="pun">-</span><span class="typ">Cache</span><span class="pln"> $upstream_cache_status</span><span class="pun">;</span>
保存并退出。
最后一步,为 nginx 的高速缓存创建一个“/var/nginx/cache”的新目录:
<span class="kwd">mkdir</span><span class="pun">-</span><span class="pln">p </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">cache</span>
步骤 7 - 配置 Nginx 的虚拟主机
在这个步骤里面,我们需要创建一个新的虚拟主机域“saitama.me”,其文档根目录为“/usr/local/www/saitama.me”,日志文件放在“/var/log/nginx”目录下。
我们必须做的第一件事情就是创建新的目录来存放虚拟主机配置文件,我们创建的新目录名为“vhost”。创建它:
<span class="kwd">cd</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span>
<span class="kwd">mkdir</span><span class="pln"> vhost</span>
创建好 vhost 目录,然后我们就进入这个目录并创建一个新的虚拟主机文件。这里我取名为“saitama.conf”:
<span class="kwd">cd</span><span class="pln"> vhost</span><span class="pun">/</span>
<span class="kwd">nano</span><span class="pun">-</span><span class="pln">c saitama</span><span class="pun">.</span><span class="pln">conf</span>
粘贴如下虚拟主机的配置:
<span class="pln">server </span><span class="pun">{</span>
<span class="com">#</span><span class="typ">Replace</span><span class="kwd">with</span><span class="pln"> your freebsd IP</span>
<span class="pln">listen </span><span class="lit">192.168</span><span class="pun">.</span><span class="lit">1.123</span><span class="pun">:</span><span class="lit">80</span><span class="pun">;</span>
<span class="com">#</span><span class="typ">Document</span><span class="typ">Root</span>
<span class="pln">root </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">saitama</span><span class="pun">.</span><span class="pln">me</span><span class="pun">;</span>
<span class="pln">index index</span><span class="pun">.</span><span class="pln">php index</span><span class="pun">.</span><span class="pln">html index</span><span class="pun">.</span><span class="pln">htm</span><span class="pun">;</span>
<span class="com">#</span><span class="typ">Domain</span>
<span class="pln">server_name www</span><span class="pun">.</span><span class="pln">saitama</span><span class="pun">.</span><span class="pln">me saitama</span><span class="pun">.</span><span class="pln">me</span><span class="pun">;</span>
<span class="com">#</span><span class="typ">Error</span><span class="kwd">and</span><span class="typ">Access</span><span class="pln"> log </span><span class="kwd">file</span>
<span class="pln">error_log </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">saitama</span><span class="pun">-</span><span class="pln">error</span><span class="pun">.</span><span class="pln">log</span><span class="pun">;</span>
<span class="pln">access_log </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">saitama</span><span class="pun">-</span><span class="pln">access</span><span class="pun">.</span><span class="pln">log main</span><span class="pun">;</span>
<span class="com">#</span><span class="typ">Reverse</span><span class="typ">Proxy</span><span class="typ">Configuration</span>
<span class="pln">location </span><span class="pun">~</span><span class="pln"> \.php$ </span><span class="pun">{</span>
<span class="pln">proxy_pass http</span><span class="pun">:</span><span class="com">//127.0.0.1:8080;</span>
<span class="kwd">include</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">proxy</span><span class="pun">.</span><span class="pln">conf</span><span class="pun">;</span>
<span class="com">#</span><span class="typ">Cache</span><span class="pln"> configuration</span>
<span class="pln">proxy_cache </span><span class="kwd">my</span><span class="pun">-</span><span class="pln">cache</span><span class="pun">;</span>
<span class="pln">proxy_cache_valid </span><span class="lit">10s</span><span class="pun">;</span>
<span class="pln">proxy_no_cache $cookie_PHPSESSID</span><span class="pun">;</span>
<span class="pln">proxy_cache_bypass $cookie_PHPSESSID</span><span class="pun">;</span>
<span class="pln">proxy_cache_key </span><span class="str">"$scheme$host$request_uri"</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="com">#</span><span class="typ">Disable</span><span class="typ">Cache</span><span class="kwd">for</span><span class="pln"> the </span><span class="kwd">file</span><span class="pln"> type html</span><span class="pun">,</span><span class="pln"> json</span>
<span class="pln">location </span><span class="pun">~*</span><span class="pun">.(?:</span><span class="pln">manifest</span><span class="pun">|</span><span class="pln">appcache</span><span class="pun">|</span><span class="pln">html</span><span class="pun">?|</span><span class="pln">xml</span><span class="pun">|</span><span class="pln">json</span><span class="pun">)</span><span class="pln">$ </span><span class="pun">{</span>
<span class="pln">expires </span><span class="pun">-</span><span class="lit">1</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="com">#</span><span class="typ">Enable</span><span class="typ">Cache</span><span class="pln"> the </span><span class="kwd">file</span><span class="lit">30</span><span class="pln"> days</span>
<span class="pln">location </span><span class="pun">~*</span><span class="pun">.(</span><span class="pln">jpg</span><span class="pun">|</span><span class="pln">png</span><span class="pun">|</span><span class="pln">gif</span><span class="pun">|</span><span class="pln">jpeg</span><span class="pun">|</span><span class="pln">css</span><span class="pun">|</span><span class="pln">mp3</span><span class="pun">|</span><span class="pln">wav</span><span class="pun">|</span><span class="pln">swf</span><span class="pun">|</span><span class="pln">mov</span><span class="pun">|</span><span class="pln">doc</span><span class="pun">|</span><span class="pln">pdf</span><span class="pun">|</span><span class="pln">xls</span><span class="pun">|</span><span class="pln">ppt</span><span class="pun">|</span><span class="pln">docx</span><span class="pun">|</span><span class="pln">pptx</span><span class="pun">|</span><span class="pln">xlsx</span><span class="pun">)</span><span class="pln">$ </span><span class="pun">{</span>
<span class="pln">proxy_cache_valid </span><span class="lit">200</span><span class="lit">120m</span><span class="pun">;</span>
<span class="pln">expires </span><span class="lit">30d</span><span class="pun">;</span>
<span class="pln">proxy_cache </span><span class="kwd">my</span><span class="pun">-</span><span class="pln">cache</span><span class="pun">;</span>
<span class="pln">access_log off</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="pun">}</span>
保存并退出。
下一步,为 nginx 和虚拟主机创建一个新的日志目录“/var/log/”:
<span class="kwd">mkdir</span><span class="pun">-</span><span class="pln">p </span><span class="pun">/</span><span class="kwd">var</span><span class="pun">/</span><span class="pln">log</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span>
如果一切顺利,在文件的根目录下创建目录 saitama.me 用作文档根:
<span class="kwd">cd</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span>
<span class="kwd">mkdir</span><span class="pln"> saitama</span><span class="pun">.</span><span class="pln">me</span>
步骤 8 - 测试
在这个步骤里面,我们只是测试我们的 nginx 和虚拟主机的配置。
用如下命令测试 nginx 的配置:
<span class="pln">nginx </span><span class="pun">-</span><span class="pln">t</span>
如果一切都没有问题,用 sysrc 命令添加 nginx 为开机启动项,并且启动 nginx 和重启 apache:
<span class="pln">sysrc nginx_enable</span><span class="pun">=</span><span class="kwd">yes</span>
<span class="pln">service nginx start</span>
<span class="pln">service apache24 restart</span>
一切完毕后,在 saitama.me 目录下,添加一个新的 phpinfo 文件来验证 php 的正常运行:
<span class="kwd">cd</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">www</span><span class="pun">/</span><span class="pln">saitama</span><span class="pun">.</span><span class="pln">me</span>
<span class="kwd">echo</span><span class="str">"<?php phpinfo(); ?>"</span><span class="pun">></span><span class="kwd">info</span><span class="pun">.</span><span class="pln">php</span>
然后访问这个域名: www.saitama.me/info.php。
Virtualhost Configured saitamame
Nginx 作为 Apache 的反向代理运行了,PHP 也同样工作了。
这是另一个结果:
测试无缓存的 .html 文件。
<span class="pln">curl </span><span class="pun">-</span><span class="pln">I www</span><span class="pun">.</span><span class="pln">saitama</span><span class="pun">.</span><span class="pln">me</span>
html with no-cache
测试有三十天缓存的 .css 文件。
<span class="pln">curl </span><span class="pun">-</span><span class="pln">I www</span><span class="pun">.</span><span class="pln">saitama</span><span class="pun">.</span><span class="pln">me</span><span class="pun">/</span><span class="kwd">test</span><span class="pun">.</span><span class="pln">css</span>
css file 30day cache
测试缓存的 .php 文件:
<span class="pln">curl </span><span class="pun">-</span><span class="pln">I www</span><span class="pun">.</span><span class="pln">saitama</span><span class="pun">.</span><span class="pln">me</span><span class="pun">/</span><span class="kwd">info</span><span class="pun">.</span><span class="pln">php</span>
PHP file cached
全部搞定。
总结
Nginx 是最受欢迎的 HTTP 和反向代理服务器,拥有丰富的功能、高性能、低内存/RAM 占用。Nginx 也用于缓存, 我们可以在网络上缓存静态文件使得网页加速,并且缓存用户请求的 php 文件。 Nginx 容易配置和使用,可以将它用作 HTTP 服务器或者 apache 的反向代理。
更多Nginx相关教程见以下内容:
Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里
via: http://linoxide.com/linux-how-to/install-nginx-reverse-proxy-apache-freebsd-10-2/
作者:Arul 译者:KnightJoker 校对:Caroline,wxy
相关推荐
某些公司会墙特定网站,如果你有一个可访问的域名和服务器,就可以通过nginx反向代理来来解决这些问题。比如现在我们用mirror.example.com镜像www.baidu.com,以下是详细操作。