美文网首页
nignx配置虚拟主机,并重启加载!

nignx配置虚拟主机,并重启加载!

作者: DragonersLi | 来源:发表于2017-06-29 19:04 被阅读74次
Paste_Image.png

根据端口号配置文件内容!


server {
    listen       83;   #端口号
    server_name quda.septwolves.cn;  #主机名
    index  index.php index.html index.htm;
    root   /data/webserver/qpl/ymall; #主机所在文件夹
    error_page  404              /404.html; # 错误页面
    location / {
        if (!-e $request_filename){
            rewrite ^/(.*)$ /index.php/$1 last;
        }
    }
     location ~ \.php($|/) {
      set $script     $uri;
        set $path_info  "";
        if ($uri ~ "^(.+?\.php)(/.+)$") {
            set $script     $1;
            set $path_info  $2;
        }
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
    include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME    $document_root$script;
        fastcgi_param  SCRIPT_NAME        $script;
        fastcgi_param  PATH_INFO          $path_info;  
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
        expires      1d;
    }
    location ~ .*\.(js|css)?$ {
        expires      12h;
    }
    location  /ngx_status {
    stub_status on;
    access_log off;
    #allow 127.0.0.1;
    #deny all;
    }
    access_log  /var/log/nginx/access_ymall.log; #日志文件
}


浏览器访问ok!

Paste_Image.png

一般配置文件

1.打开nginx.conf文件,底部添加代码:include 2018qpl/*.conf;
2.nginx.conf同级新建文件夹2018qpl,再新建配置文件qpl.243.com.conf,文件代码如下:

server {
    listen       80;
    server_name qpl.243.com;  
    index  default.html index.php index.html index.htm;
    root   /usr/share/nginx/html/2018qpl/qpl;
    error_page  404              /404.html;
    location / {
        if (!-e $request_filename){
            rewrite ^/(.*)$ /index.php/$1 last;
        }
    }
     location ~ \.php($|/) {
      set $script     $uri;
        set $path_info  "";
        if ($uri ~ "^(.+?\.php)(/.+)$") {
            set $script     $1;
            set $path_info  $2;
        }
        root           /usr/share/nginx/html/2018qpl/qpl;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME    $document_root$script;
        fastcgi_param  SCRIPT_NAME        $script;
        fastcgi_param  PATH_INFO          $path_info;  
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|sir)$ {
        expires      1d;
    }
    location ~ .*\.(js|css)?$ {
        expires      12h;
    }
    error_log  /usr/share/nginx/html/2018qpl/qpl/qpl_error.log;
    access_log  /usr/share/nginx/html/2018qpl/qpl/qpl_access.log  main;
}

image.png

查看nginx目录,配置完重启!

 

#查看nginx是否启动的四种方法:
netstat -anp | grep :80   #使用netstat命令 
lsof -i:80 #使用lsof命令
ps -C nginx -o pid  #直接查看进程id
 ps  -ef | grep nginx  #用ps -ef列出进程列表,然后通过grep过滤

#重启加载:
cd /usr/local/nginx/sbin   #进入nginx
./nginx -s reload          #重启加载配置

Paste_Image.png

如果是测试服务器,本地访问,还需在本机host文件添加配置:

image.png

相关文章

网友评论

      本文标题:nignx配置虚拟主机,并重启加载!

      本文链接:https://www.haomeiwen.com/subject/kjrvcxtx.html