Home > php教程 > php手册 > first nginx & php

first nginx & php

WBOY
Release: 2016-06-06 19:36:11
Original
1122 people have browsed it

pc-nginx-apache(for test install easy) 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; } }} server { location

 

pc->nginx->apache(for test install easy)

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;
        }
    }
}
Copy after login
<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>
Copy after login

env

kernel:3.10.0-123.el7.x86_64

nginx version: nginx/1.4.7   ./configure --prefix=/usr/local/nginx/ --with-pcre=/usr/local/pcre-7.9/(source code path) --with-zlib=/usr/local/zlib-1.2.8/(source code path)

php version :5.5.20 auto enable fastcgi    ./configure --prefix=/usr/local/php --enable-debug --enable-fpm

config

first nginx & phpfirst nginx & php

<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> }
Copy after login
nginx.conf

/usr/local/php/sbin/php-fpm

/usr/local/nginx/sbin/nginx 

sysctl stop firewalld.service
systemctl stop firewalld.service

result

 

[root@localhost conf]# curl 127.0.0.1 | head
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 56014 0 56014 0 0 9.8M 0 --:--:-- --:--:-- --:--:-- 10.6M


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template