Created
July 8, 2013 03:55
-
-
Save azhai/5946142 to your computer and use it in GitHub Desktop.
Nginx下PHP网站配置,使用子域名
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#生效 | |
#nginx -s reload | |
log_format sess '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for" "$var_sessid"'; | |
server { | |
listen 80; | |
server_name example.com ~^(?<subdomain>[a-z0-9]+)\.example\.com$; | |
charset utf-8; | |
if ($subdomain = "") { | |
set $subdomain "www"; | |
} | |
root /var/www/$subdomain; | |
# case insensitive | |
lower $lower_uri "$uri"; | |
try_files $uri $lower_uri $lower_uri.html; | |
set $var_sessid "-"; | |
if ( $http_cookie ~* "PHPSESSID=(\S+)(;.*|$)") | |
{ | |
set $var_sessid $1; | |
} | |
access_log logs/$subdomain.example.access.log sess; | |
#error_page 404 /404.html; | |
# redirect server error pages to the static page /50x.html | |
# | |
#error_page 500 502 503 504 /50x.html; | |
#location = /50x.html { | |
# root html; | |
#} | |
if ($request_uri ~* ^.*\.(svn|git|hg|bzr|cvs).*$) { | |
return 404; | |
} | |
location ~* ^.+\.(css|js|jpg|png|gif|ico|swf|pdf|txt|xlsx)$ { | |
access_log off; | |
expires 30d; | |
} | |
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
# | |
location / { | |
#auth_basic "Restricted"; | |
#auth_basic_user_file authes/example; | |
try_files $uri $uri/ /index.php?$query_string; | |
#fastcgi_pass 127.0.0.1:9000; | |
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
} | |
#Index file | |
#location ~* /$ { | |
# index index.html; | |
#} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment