配置静态网站

server {
listen 80;
server_name localhost;
location /{
root html; #默认Nginx站点
index index.html index.htm;
}
location ^~ /javabs/{
alias /www/javabs/; #自定义站点,注意都是以斜杠结尾 文件路径自定义不一定是javabs
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

配置动态网站

配置JSP

 server {
listen 80;
server_name blog.javabs.cn;
location / {
index index.jsp;
#Tomcat访问地址
proxy_pass http://127.0.0.1:8080;
}
location /solr {
#类似虚拟目录 指向一个具体项目
proxy_pass http://127.0.0.1:8180$request_uri;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

配置PHP

server{
listen 80;
server_name javabs.cn www.javabs.cn;
root /mnt/www/domains/javabs.cn/public_html;
index index.php index.html;
error_page 404 = http://www.javabs.cn/404.html;
location = /500.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
access_log /usr/local/nginx/logs/javabs.cn.access.log main;#日志
}
location ~ /\.ht {
deny all;#拒绝访问htaccess文件
}
}

作者: 杨校