Nginx學習之反向代理
配置靜態網站
server {
listen 80;
server_name localhost;
location /{
root html; #默認Nginx站點
index index.html index.htm;
}
location ^~ /itstyle/{
alias /www/itstyle/; #自定義站點,注意都是以斜杠結尾 文件路徑自定義不一定是itstyle
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.52itstyle.com;
location / {
index index.jsp;
#Tomcat訪問地址
proxy_pass https://127.0.0.1:8080;
}
location /solr {
#類似虛擬目錄 指向一個具體項目
proxy_pass https://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 52itstyle.com www.52itstyle.com;
root /mnt/www/domains/52itstyle.com/public_html;
index index.php index.html;
error_page 404 = https://www.52itstyle.com/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/52itstyle.com.access.log main;#日誌
}
location ~ /\.ht {
deny all;#拒絕訪問htaccess文件
}
}
最後更新:2017-04-10 11:00:02