linux centos nginx 配置虚礼主机

来源:互联网 发布:flash编程视频教程 编辑:程序博客网 时间:2024/05/19 14:36

linux centos nginx 配置虚礼主机 nginx.conf配置文件
vhost/*.conf 可以用usr/local/ngx_openresty/nginx/sbin/nginx -t来检测配置文件是否正确
启动nginx :

/usr/local/ngx_openresty/nginx/sbin/nginx

强行杀掉nginx:

killall nginx

查看进程:

ps -ef|grep nginx

然后得到nginx master的进程pid,注意master的

然后可以用它来平滑启动nginx,就是不杀掉nignx,而再次启动nginx

kill -hup MasterPid


netstat -anltp 可以查看系统各种进程参数


nginx配置虚礼主机配置:

nginx.conf配置文件:


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#这个注释掉也可以,那就以默认的拥有用户及组启动
user www www;
#这个参数最好与服务器的核数一样
worker_processes 1;
 
error_log  /logs/nginx/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
 
events {
    use epoll;
    worker_connections  1024;
}
 
#我把那些注释掉的删掉了
#这里是没有反向代理的配置文件格式
 
http {
    include       mime.types;
    #这个就是设置记录日志文件格式
    #有远程主机的ip,用户名,时间,请求url,请求状态,返回结果,浏览器信息,代理服务器ip等
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                            '$status $body_bytes_sent "$http_referer" '
                            '"$http_user_agent" "$http_x_forwarded_for"';
 
    sendfile        on;
    tcp_nopush     on;
 
    keepalive_timeout  65;
    client_max_body_size   100m;
 
    #下面这句话,就是与nginx.conf一样目录下面,新建一个目录vhost然后再在里面
    #新建各种虚礼主机的配置文件,注意配置文件一定要以.conf结尾
 
    include vhost/*.conf;
}


yourConf.conf:


?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
server {
    listen       80;
    #可以有多个如:yourDomain1.com yourDomain2.com yourDomain3.com;空格隔开
    server_name  yourDomain.com;
    #这里加上index.php表示默认加载index.php
    index index.html index.htm index.php;
    #这个指向你的网站的代码根目录
    root /www/yourDemo;
     
    client_max_body_size   50m;
 
    #这个是定义日志文件名,可以随意,但是要注意日志目录可以写
    #main 是nginx.conf里面定义的,表示日志格式
    access_log  /www/logs/yourDomain.com.log  main;
 
    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
 
    #如果所访问的文件不存在,就跳到首页访问index.php
    #当然,如果你的代码里面,对这种错误有处理,就去访问你自己定义的error.php页面
    if(!-e $request_filename){
        rewrite (.*) /index.php break;
    }
    #这个就是缓存这些格式的文件的时间
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|attach)$
    {
      expires      30d;
    }
    #这个是nginx的一个bug修复,赶紧加上吧
    if($request_uri ~ " ") {
        return444;
    }
    #这个就是缓存这些格式的文件的时间
    location ~ .*\.(js|css)?$
    {
      expires      1h;
    }
 
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #设置解析php的php引擎
    location ~ .*\.php$ {
        #root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include        fastcgi.conf;
        client_max_body_size 60m;
        set $path_info "";
 
        if($request_uri ~ "^(.+?\.php)(/.+)$") {
            set $path_info $2;
        }
        if($request_uri ~ "^(.+?\.php)(.*)(\?.*)$") {
            set $path_info $2;
        }
    }
}
0 0
原创粉丝点击