pc-nginx-apache(用于测试安装) http { upper myapp1 { //---用于平衡服务器 srv1.example.com;服务器 srv2.example.com;服务器 srv3.example.com; } 服务器 { 监听 80;位置/{ proxy_pass http://myapp1; } }} 服务器 { 位置
http { upstream myapp1 { //---for balance server srv1.example.com; server srv2.example.com; server srv3.example.com; } server { listen 80; location / { proxy_pass http://myapp1; } } }
<br><br><br>server { location / { proxy_pass http://localhost:8080/; //---to apache } location ~ \.(gif|jpg|png)$ { //---to local root /data/images; } }<br><br><span>------------------------------------------- </span>
内核:3.10.0-123.el7.x86_64
nginx版本:nginx/1.4.7 ./configure --prefix=/usr/local/nginx/ --with-pcre=/usr/local/pcre-7.9/(源代码路径) --with-zlib =/usr/local/zlib-1.2.8/(源码路径)
php 版本:5.5.20 自动启用 fastcgi ./configure --prefix=/usr/local/php --enable-debug --enable-fpm
<span> 1</span> <span>#user nobody; </span><span> 2</span> worker_processes <span>1</span><span>; </span><span> 3</span> <span> 4</span> #error_log logs/<span>error.log; </span><span> 5</span> #error_log logs/<span>error.log notice; </span><span> 6</span> #error_log logs/<span>error.log info; </span><span> 7</span> <span> 8</span> #pid logs/<span>nginx.pid; </span><span> 9</span> <span>10</span> <span>11</span> <span>events { </span><span>12</span> worker_connections <span>1024</span><span>; </span><span>13</span> <span>} </span><span>14</span> <span>15</span> <span>16</span> <span>http { </span><span>17</span> <span> include mime.types; </span><span>18</span> default_type application/octet-<span>stream; </span><span>19</span> <span>20</span> #log_format main <span>'</span><span>$remote_addr - $remote_user [$time_local] "$request" </span><span>'</span> <span>21</span> # <span>'</span><span>$status $body_bytes_sent "$http_referer" </span><span>'</span> <span>22</span> # <span>'</span><span>"$http_user_agent" "$http_x_forwarded_for"</span><span>'</span><span>; </span><span>23</span> <span>24</span> #access_log logs/<span>access.log main; </span><span>25</span> <span>26</span> <span> sendfile on; </span><span>27</span> <span> #tcp_nopush on; </span><span>28</span> <span>29</span> #keepalive_timeout <span>0</span><span>; </span><span>30</span> keepalive_timeout <span>65</span><span>; </span><span>31</span> <span>32</span> <span> #gzip on; </span><span>33</span> <span>34</span> <span> server { </span><span>35</span> listen <span>80</span><span>; </span><span>36</span> <span> server_name localhost; </span><span>37</span> <span>38</span> #charset koi8-<span>r; </span><span>39</span> <span>40</span> #access_log logs/<span>host.access.log main; </span><span>41</span> <span>42</span> location /<span> { </span><span>43</span> <span> root html; </span><span>44</span> <span> index index.php index.html index.htm; </span><span>45</span> <span> } </span><span>46</span> <span>47</span> #error_page <span>404</span> /<span>404</span><span>.html; </span><span>48</span> <span>49</span> # redirect server error pages to the <span>static</span> page /<span>50x.html </span><span>50</span> <span> # </span><span>51</span> error_page <span>500</span> <span>502</span> <span>503</span> <span>504</span> /<span>50x.html; </span><span>52</span> location = /<span>50x.html { </span><span>53</span> <span> root html; </span><span>54</span> <span> } </span><span>55</span> <span>56</span> # proxy the PHP scripts to Apache listening on <span>127.0</span>.<span>0.1</span>:<span>80</span> <span>57</span> <span> # </span><span>58</span> #location ~<span> \.php$ { </span><span>59</span> # proxy_pass http:<span>//</span><span>127.0.0.1;</span> <span>60</span> <span> #} </span><span>61</span> <span>62</span> # pass the PHP scripts to FastCGI server listening on <span>127.0</span>.<span>0.1</span>:<span>9000</span> <span>63</span> <span> # </span><span>64</span> location ~<span> \.php$ { </span><span>65</span> root /usr/local/nginx/<span>html; </span><span>66</span> fastcgi_pass <span>127.0</span>.<span>0.1</span>:<span>9000</span><span>; </span><span>67</span> <span> fastcgi_index index.php; </span><span>68</span> <span> include fastcgi.conf; </span><span>69</span> <span> } </span><span>70</span> <span>71</span> # deny access to .htaccess files, <span>if</span> Apache<span>'</span><span>s document root</span> <span>72</span> # concurs with nginx<span>'</span><span>s one</span> <span>73</span> <span> # </span><span>74</span> #location ~ /<span>\.ht { </span><span>75</span> <span> # deny all; </span><span>76</span> <span> #} </span><span>77</span> <span> } </span><span>78</span> }
/usr/local/php/sbin/php-fpm
/usr/local/nginx/sbin/nginx
sysctl 停止firewalld.service
systemctl 停止firewalld.service
结果
[root@localhostconf]#curl 127.0.0.1 | head
% 总计 % 接收百分比 % Xferd 平均速度 时间 时间 当前
Dload 上传总花费左速度
100 56014 0 56014 0 0 9.8M 0 --:--:-- --:-- :-- --:--:-- 10.6M