安裝上nginx后
注意后nginx.conf 中的這么幾行
error_log /var/log/nginx/error.log; 日志,這個很有用
include /etc/nginx/conf.d/*.conf; 引用配置,可以對不同的域名進行不同的配置
現在我就在conf.d文件夾里創建了一個以.conf擴展名的文件 (記住一定是.conf)
內容如下
server {
listen 端口號;
charset utf-8;
server_name 域名;
index index.html index.htm index.php;
location / {
set $http_origin '*';
proxy_pass http://127.0.0.1:80;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /dist/ {
root /全路徑例如aa/; #這里的路徑配置如果是aa 則aa中需要包含dist這個文件,如果在路徑上出現了問題建議查看日志文件
index index.html index.htm;# 這里因為我配置的是跑html文件的
}
location /sw/ {#配置的跑php文件的
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
root /全路徑例如bb/;#原理同上
index index.html index.htm index.php;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico|m3u8)$ { #這個配置很關鍵 沒有跑不了圖片的靜態資源等
root /aa/; #這是網站根目錄 也就是靜態資源的根目錄
if (-f $request_filename) {
expires 1d;
break;
}
}
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
}
以上關於一個域名下配置了跑php html 圖片資源 多個目錄下的操作