前面我们已经搭建好了LNMP环境:http://1015489314.blog.51cto.com/8637744/1688048
下面我们基于LNMP来搭建一个Discuz!论坛
一、安装Discuz!
1、新建目录来存放网页等
[[email protected] ~]# mkdir /data/www[[email protected] ~]# cd /data/www [[email protected] www]# wget http://download.comsenz.com/DiscuzX/3.2/Discuz_X3.2_SC_GBK.zip //下载最新版本的Discuz![[email protected] www]# unzip Discuz_X3.2_SC_GBK.zip //解压[[email protected] www]# lsDiscuz_X3.2_SC_GBK.zip readme upload utility
2、程序文件会放于upload下,所以全部移到www目录下,并且删除多余的文件。
[[email protected] www]# mv upload/* ./ [[email protected] www]# lsadmin.php connect.php favicon.ico install readme template utilityapi cp.php forum.php member.php robots.txt uc_clientapi.php crossdomain.xml group.php misc.php search.php uc_serverarchiver data home.php plugin.php source uploadconfig Discuz_X3.2_SC_GBK.zip index.php portal.php static userapp.php[[email protected] www]# rm -rf readme/ utility/ upload/ Discuz_X3.2_SC_GBK.zip
3、修nginx的主配置文件,虚拟主机单独放于一个文件中
[[email protected] www]# vim /usr/local/nginx/conf/nginx.conf
user nobody nobody;worker_processes 2;error_log /usr/local/nginx/logs/nginx_error.log crit;pid /usr/local/nginx/logs/nginx.pid;worker_rlimit_nofile 51200;events{ use epoll; worker_connections 6000;}http{ include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 3526; server_names_hash_max_size 4096; log_format combined_realip ‘$remote_addr $http_x_forwarded_for [$time_local]‘ ‘$host "$request_uri" $status‘ ‘"$http_referer" "$http_user_agent"‘; sendfile on; tcp_nopush on; keepalive_timeout 30; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; connection_pool_size 256; client_header_buffer_size 1k; large_client_header_buffers 8 4k; request_pool_size 4k; output_buffers 4 32k; postpone_output 1460; client_max_body_size 10m; client_body_buffer_size 256k; client_body_temp_path /usr/local/nginx/client_body_temp; proxy_temp_path /usr/local/nginx/proxy_temp; fastcgi_temp_path /usr/local/nginx/fastcgi_temp; fastcgi_intercept_errors on; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 8k; gzip_comp_level 5; gzip_http_version 1.1; gzip_types text/plain application/x-javascript text/css text/htm application/xml; include vhosts/*.conf; //添加该行,并剪切出虚拟主机配置}
在主配置文件末尾加上include vhosts/*.conf;并且剪切出下面的内容作为虚拟主机的配置文件,单独放于 /usr/local/nginx/conf/vhosts文件下中
[[email protected] www]# mkdir /usr/local/nginx/conf/vhosts
[[email protected] www]# cd /usr/local/nginx/conf/vhosts
[[email protected] vhosts]# vim default.conf //写入下面的内容
server{ listen 80 default; server_name localhost; index index.html index.htm index.php; root /tmp/1233/; deny all;}
[[email protected] vhosts]# mkdir /tmp/1233
[[email protected] vhosts]# /usr/local/nginx/sbin/nginx -t //检查nginx是否配置错误
[[email protected] vhosts]# /etc/init.d/nginx reload //重新加载nginx
因为vhosts目录下自带了默认的虚拟主机配置文件,访问时候会自动跳转到默认的虚拟主机,为了安全起见我们禁止所有的访问,使其访问我们自己设置的网页。添加default,表示默认主机;路径修改为空目录/tmp/1233/;deny all表示禁止所有访问,会报403错误。
测试下:[[email protected] vhosts]# curl -x127.0.0.1:80 www.baidu.com
结果如下图所示:
4、新建虚拟主机
如果我们有一个新的网站,则需新建一个虚拟主机
[[email protected] vhosts]# vim test.conf
server
{
listen 80;
server_name test.com;
index index.html index.htm index.php;
root /data/www;
location ~ \.php$ {
include fastcgi_params;
# fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
}
}
重新加载nginx服务
[[email protected] vhosts]# /etc/init.d/nginx reload
测试;curl -x127.0.0.1:80 test.com -I