nginx伺服器配置網站模板
server {
listen 127.0.0.1:80;
server_name www.test.com test.com;
if ( $host = 'test.com' ) {
rewrite ^/(.*)$ http://www.test.com/$1 permanent;
}
set $ROOT_PATH /home/sites/test/public;
location = / {
root $ROOT_PATH;
index index.php;
try_files $uri $uri/ /index.php?$query_string;
}
root /home/sites/test/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php index.html index.htm;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ROOT_PATH$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
access_log /home/log/nginx/access/www.test.com.access.log;
error_log /home/log/nginx/error/www.test.com.error.log;
}
#####################################################
若該域名有老程式碼,且打算繼續使用
server {
listen 127.0.0.1:80;
server_name www.test.com test.com;
if ( $host = 'test.com' ) {
rewrite ^/(.*)$ http://www.test.com/$1 permanent;
}
set $ROOT_PATH /home/sites/test/public/;
location = / {
root $ROOT_PATH;
index index.php;
try_files $uri $uri/ /index.php?$query_string;
}
#####引用老程式碼配置,用正則表示式判斷路由引數,不符合則跳入老程式碼
location ~ ^/(?!school/|news/|search/|index\.php|css|js|images|fonts|baidu_verify|sitemap|robots).*$ {
proxy_pass http://proxypass.test.com;
}
root /home/sites/test/public/;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php index.html index.htm;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ROOT_PATH$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
access_log /home/log/nginx/access/www.test.com.access.log;
error_log /home/log/nginx/error/www.test.com.error.log;
}