Linux7下配置Nginx站点.

今天闲来无事,把服务器重新配置了一下,作为开发者,实际上很多人都是长时间不去配置服务器的,所以曾经很多东西又忘掉了差不多.

特在此分享一下配置成功后的配置文件内容.

其实配置后的文件内容很简单,也没有太多啰嗦的地方,不需要的东西都删掉了.

实际环境:

操作系统:Linux 7

Nginx版本:1.14

PHP7.2

NGINX配置

主配置文件:nginx.conf

user  root;
worker_processes  1;

error_log   logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    
    include       mime.types;
    default_type  application/octet-stream;
	
    sendfile           on;
    keepalive_timeout  65;

    #gzip  on;
	
    #引入外部的配置文件.
    include conf.d/*.conf; 
}

外部引用文件:music.xingzhi.com.conf

server {
    listen       80;
    server_name  localhost;
    #站点的物理路径
    root /data/www/music.xingzhi.com;
    #站点默认访问页面
    index index.php index.html;    
    
    location / {
        #此处是针对thinkphp 的url重写规则进行配置.
        if (!-e $request_filename) {
           rewrite  ^/(.*)$  /index.php/$1  last;
           break;
        }
    }
    #此处配置是针对解析php进行的配置.
    location ~ \.php {
        #你站点的实际物理路径
        root           /data/www/music.xingzhi.com;
        #此处配置FastCGI的IP地址和端口.
        fastcgi_pass   127.0.0.1:9000;
        #指定fastcgi对PHP的默认访问.
        fastcgi_index  index.php;
        #此处是引入fastcgi配置文件.
    include        fastcgi.conf;
    #一下两处是设置fastcgi与php之间的解析
    set $fastcgi_script_name2 $fastcgi_script_name;
        if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
            set $fastcgi_script_name2 $1;
            set $path_info $2;
        }
    #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param   PATH_INFO $path_info;
    fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;
    fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2;
        include         fastcgi_params;
    }
    #允许站点解析缓存js|css资源文件.
    location ~ .*\.(js|css)?$ {
        expires 30d;
    }
    #允许nginx解析缓存图片.
    location ~ .*\.(gif|jpg|jpeg|png|bmp)$ { 
        expires 60s; 
    }
}

 

  

 

posted @ 2018-09-12 12:54  迦南邪恋  阅读(382)  评论(0编辑  收藏  举报