开发者社区> 问答> 正文

教程101之系统配置

教程101之系统配置



系统配置将按照功能分类来写 一功能为导向 并给出配置文件模板 因为配置文件实在是太多了 没办法一一讲清
不会再突出系统差别 因为不同系统下配置文件基本通用的 只有特殊位置会给出提示


Apache


1.创建虚拟主机


虚拟主机分为两种:
1.IP相同,端口不同,通过端口判断
2.IP相同,端口相同,域名不同


首先来说第一种,端口不同的


模板是:
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /var/html/
    ServerName xxx.xxx.xxx
    ErrorLog logs/xxxx-error_log
    CustomLog logs/xxxx-access_log common
</VirtualHost>
那么如何自定义呢?


首先80修改为你自己定义的端口,范围最好是10000之后655535之前。
将DocumentRoot以及ServerName设置为网站对应的根目录以及域名
然后在指定目录下创建<任意名字>.conf


Ubuntu: /etc/apache/sites-availabe/
Centos: /etc/httpd/con.d/


最后需要在apache的主文件中添加监听端口。
Ubuntu: /etc/apache/apache.conf
Centso: /etc/httpd/conf/httpd.conf
在文件最尾部添加Listen <端口号>


之后在Ubuntu需要执行a2ensite  <任意名字>
上面命令的意思是开启这个虚拟主机
最后在服务器中重启apache服务器即可。


第二种基于域名的差不多

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot /var/html/
    ServerName xxx.xxx.xxx
    ErrorLog logs/xxxx-error_log
    CustomLog logs/xxxx-access_log common
</VirtualHost>

   端口号不用改 将DocumentRoot以及ServerName设置为网站对应的根目录以及域名


Ubuntu中需要添加NameVirtualHost *:80到配置主文件
Centos中需要在htppd.conf中注释掉NameVirtualHost *:80这句话


然后在指定目录下创建<任意名字>.conf


Ubuntu: /etc/apache/sites-availabe/
Centos: /etc/httpd/con.d/


之后在Ubuntu需要执行a2ensite  <任意名字>
最后在服务器中重启apache服务器即可。


Nginx
#######################################################################
#
# This is the main Nginx configuration file.  
#
# More information about the configuration options is available on
#   * the English wiki - http://wiki.nginx.org/Main
#   * the Russian documentation - http://sysoev.ru/nginx/
#
#######################################################################


#----------------------------------------------------------------------
# Main Module - directives that cover basic functionality
#
#   http://wiki.nginx.org/NginxHttpMainModule
#
#----------------------------------------------------------------------


user              nginx;
worker_processes  1;


error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;


pid        /var/run/nginx.pid;




#----------------------------------------------------------------------
# Events Module
#
#   http://wiki.nginx.org/NginxHttpEventsModule
#
#----------------------------------------------------------------------


events {
    worker_connections  1024;
}




#----------------------------------------------------------------------
# HTTP Core Module
#
#   http://wiki.nginx.org/NginxHttpCoreModule
#
#----------------------------------------------------------------------


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';


    access_log  /var/log/nginx/access.log  main;


    sendfile        on;
    #tcp_nopush     on;


    #keepalive_timeout  0;
    keepalive_timeout  65;


    #gzip  on;
    
    #
    # The default server
    #
    server {
        listen       80;
        server_name  _;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }


        error_page  404              /404.html;
        location = /404.html {
            root   /usr/share/nginx/html;
        }


        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }


        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}


        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }


        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # Load config files from the /etc/nginx/conf.d directory
    include /etc/nginx/conf.d/*.conf;


}
上面就是一个完整的虚拟主机配置文件 看起来比较多 其实需要修改的只有一下一部分
server {
        listen       80;
        server_name  _;


        #charset koi8-r;


        #access_log  logs/host.access.log  main;


        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }


80可以修改为你想爱那个对应的端口
server_name 后面跟网站域名
root后面的改成网站的目录所在


之后创建名为<名称>.conf的文件到以下路径:
Ubuntu: /etc/nginx/sites-enabled/
Centos: /etc/nginx/conf.d/
然后重启Nginx服务器就好


PHP


1.如何修改上传文件大小限制


upload_max_filesize = 5M
修改后面的数值来修改允许上传文件大小


配置文件位置


Ubuntu:


使用apache:


/etc/php5/apache2/php.ini


使用Nginx:


/etc/php5/fpm/php.ini


Centos:


/etc/php.ini


Mysql:


暂时还没想好 涉及的都比较专业了 计划放在中级教程了 如果大家有需要可以提出来


想到的就上面那些 如果大家还有其他需要实现的公呢个可以跟贴提出来 我会不断把新的问题加入进去的
如果有错误的地方也请大家提出来
截图的话以后慢慢来完善 最近事情多而且得了胃出血 估计写的速度会大幅度降低了 大家见谅



展开
收起
twl007 2013-04-26 23:19:43 14653 0
7 条回答
写回答
取消 提交回答
  • 支持,第一页顶楼住好人!
    2013-05-01 00:59:22
    赞同 展开评论 打赏
  • Re教程101之系统配置
    谢楼主very much
    2013-04-30 18:40:15
    赞同 展开评论 打赏
  • ...

    亲耐的。下次编辑帖子,记得将排版行距也修正下。

    让用户更便捷阅读。。
    2013-04-27 09:06:54
    赞同 展开评论 打赏
  • 版主太给力了
    2013-04-27 08:42:50
    赞同 展开评论 打赏
  • 学习下 多谢分享
    2013-04-26 23:32:24
    赞同 展开评论 打赏
  • 回 1楼(yyd521) 的帖子

    -------------------------

    回 5楼(xinicn) 的帖子
    恩…… 的确是空的有点多了…… 囧啊 会精良让行距均匀一些
    2013-04-26 23:31:20
    赞同 展开评论 打赏
  • 沙发来支持
    2013-04-26 23:24:06
    赞同 展开评论 打赏
滑动查看更多
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载