|
| 1 | +server { |
| 2 | + listen 80; |
| 3 | + server_name localhost www.site1.com; |
| 4 | + root /var/www/html/site1; |
| 5 | + index index.php index.html index.htm; |
| 6 | + #charset koi8-r; |
| 7 | + location / { |
| 8 | + index index.php index.html index.htm; |
| 9 | + #如果请求既不是一个文件,也不是一个目录,则执行一下重写规则 |
| 10 | + if (!-e $request_filename) |
| 11 | + { |
| 12 | + #地址作为将参数rewrite到index.php上。 |
| 13 | + rewrite ^/(.*)$ /index.php?s=$1; |
| 14 | + #若是子目录则使用下面这句,将subdir改成目录名称即可。 |
| 15 | + #rewrite ^/subdir/(.*)$ /subdir/index.php?s=$1; |
| 16 | + } |
| 17 | + } |
| 18 | + access_log /dev/null; |
| 19 | + #access_log /var/log/dnmp/nginx.site1.access.log main; |
| 20 | + error_log /var/log/dnmp/nginx.site1.error.log warn; |
| 21 | + |
| 22 | + #error_page 404 /404.html; |
| 23 | + |
| 24 | + # redirect server error pages to the static page /50x.html |
| 25 | + # |
| 26 | + error_page 500 502 503 504 /50x.html; |
| 27 | + location = /50x.html { |
| 28 | + root /usr/share/nginx/html; |
| 29 | + } |
| 30 | + |
| 31 | + # proxy the PHP scripts to Apache listening on 127.0.0.1:80 |
| 32 | + # |
| 33 | + #location ~ \.php$ { |
| 34 | + # proxy_pass http://127.0.0.1; |
| 35 | + #} |
| 36 | + |
| 37 | + # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 |
| 38 | + # |
| 39 | + location ~ \.php$ { |
| 40 | + include fastcgi_params; |
| 41 | + set $path_info ""; |
| 42 | + #定义变量 $real_script_name,用于存放真实地址 |
| 43 | + set $real_script_name $fastcgi_script_name; |
| 44 | + fastcgi_pass php:9000; |
| 45 | + fastcgi_index index.php; |
| 46 | + include fastcgi_params; |
| 47 | + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; |
| 48 | + if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { |
| 49 | + #将文件地址赋值给变量 $real_script_name |
| 50 | + set $real_script_name $1; |
| 51 | + #将文件地址后的参数赋值给变量 $path_info |
| 52 | + set $path_info $2; |
| 53 | + } |
| 54 | + fastcgi_intercept_errors on; |
| 55 | + } |
| 56 | + |
| 57 | + # deny access to .htaccess files, if Apache's document root |
| 58 | + # concurs with nginx's one |
| 59 | + # |
| 60 | + #location ~ /\.ht { |
| 61 | + # deny all; |
| 62 | + #} |
| 63 | +} |
| 64 | + |
0 commit comments