webServer安装及配置详情

             **apache 基本操作**

安装 yum install httpd
启动         service httpd start
停止 service httpd stop

安装apache后 ,cd /etc/httpd/conf
vim http

  <VirtualHost *:80>
        ServerName www.nana.com
        DocumentRoot /data/www
        <Directory "/data/www">
                Options Indexes FollowSymLinks
                AllowOverride None
                Require all granted
        </Directory>
        //伪静态
         <IfModule mod_rewrite.c>
             RewriteEngine On
             RewriteRule ^(.*).html$ index.html
         </IfModule>
</VirtualHost>

如果不行的话
执行 sudo setenforce 0

host 文件位置  C:\Windows\System32\drivers\etc 
建立多级目录
mkdir -p xxx/xxx/xxx

    **nginx 基本操作**

安装 yum install nginx
启动 service nginx start (systemctl start nginx.service)
停止 service nginx stop (systemctl stop nginx.service)
重载 service nginx reload (systemctl reload nginx.service)
nginx拓展知识
虚拟主句
多域名,多端口
伪静态
日志格式化
反向代理和负载均衡
调试技巧

安装nginx
首先要添加centos 7 nginx yum 资源库
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum install nginx

server {
listen 80;
server_name www.nana.com
root /data/www;
index index.html index.htm;
location / {
rewrite ^(.*).html$ /index.html;
}
}

反向代理

要代理的ip 或域名
upstream nana_hosts {
server 192.169.1.122 weight=5
server 192.169.1.154 weight=1
}

server {
listen 80;
server_name www.nana.com
root /data/www;
index index.html index.htm;
access_log /var/log/nginx/access_nana.log nana;
location / {
rewrite ^(.*).html$ /index.html;
反向代理设置
proxy_set_header Host www.nana.com;
proxy_pass http://nana_hosts;
}
}

例如

server {
server_name xw.xinwangd.com;
listen 80;
index index.php index.html index.htm;
root /var/www/html/www.xinwangd.com;

location ~* /Public/share/js/uploadify/uploadify.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  PHP_VALUE         open_basedir=$document_root:/tmp/:/proc/;
    include        fastcgi_params;
}

location ~* /(Core|Upload|Public|images|cache|media|logs|tmp)/.*.(php|asp|jsp|pl|py|sh|cgi)$ {
    return 403;
    error_page 403 /403.html;
}

location / {
    if ( !-e $request_filename ) {
        rewrite "^/(.*)$" /index.php?s=/$1 last;
    }
}
location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  PHP_VALUE         open_basedir=$document_root:/tmp/:/proc/;
    include        fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
    expires 30d;
}

location ~ .*\.(js|css)?$ {
    expires 12h;
}

access_log /mnt/weblog/xinwangd_access.log;
error_log  /mnt/weblog/xinwangd_error.log;

}

你可能感兴趣的:(linux服务器)