Linux+Nginx Web Server+Mysql+PHP

12.安装nginx所需的pcre库:

tar -zxvf pcre-8.31.tar.gz

cd pcre-8.31

./configure

make && make install

cd ../

13.安装Nginx:

tar -zxvf nginx-1.5.8.tar.gz

cd nginx-1.5.8

./configure --user=www --group=www  --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

make && make install

cd ../

14.创建nginx日志文件:

mkdir -p /data1/logs

chmod +w /data1/logs/

chmod +w /data1/logs

chown -R www:www /data1/logs

15.创建及编辑nginx配置文件:

cd /usr/local/nginx/conf/

cp nginx.conf nginx.conf.bak

vim nginx.conf:

more nginx.conf|grep -v ‘^$‘|grep -v ‘#‘

user www www;

worker_processes 8;

error_log /data1/logs/nginx_error.log crit;

pid       logs/nginx.pid;

worker_rlimit_nofile 65535;

events {

use epoll;

worker_connections  65535;

}

http {

include       mime.types;

default_type application/octet-stream;

log_formataccess ‘$remote_addr - $remote_user [$time_local] "$request" ‘

‘$status $body_bytes_sent "$http_referer" ‘

‘ "$http_user_agent" $http_x_forwarded_for‘;

access_log/data1/logs/access.log access;

sendfile        on;

keepalive_timeout  60;

server {

listen       80;

server_name  192.168.1.109;

location / {

root   html;

index  index.html index.htmindex.php;

}

error_page   500 502 503 504  /50x.html;

location = /50x.html {

root   html;

}

location ~ .*\.(php|php5)?$ {

fastcgi_pass   127.0.0.1:9000;

fastcgi_index  index.php;

include        fcgi.conf;

}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*\.(js|css)$

{

expires 1h;

}

}

}

16.在/usr/local/nginx/conf/目录中创建fcgi.conf文件:

cp fastcgi.conf fcgi.conf

cp fcgi.conf fcgi.conf.bak

vim fcgi.conf,内容如下:

more fcgi.conf|grep -v ‘^$‘|grep -v ‘#‘

fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;

fastcgi_param QUERY_STRING       $query_string;

fastcgi_param REQUEST_METHOD    $request_method;

fastcgi_param CONTENT_TYPE       $content_type;

fastcgi_param CONTENT_LENGTH    $content_length;

fastcgi_param SCRIPT_NAME       $fastcgi_script_name;

fastcgi_param REQUEST_URI        $request_uri;

fastcgi_param DOCUMENT_URI       $document_uri;

fastcgi_param DOCUMENT_ROOT      $document_root;

fastcgi_param SERVER_PROTOCOL   $server_protocol;

fastcgi_param HTTPS              $httpsif_not_empty;

fastcgi_param GATEWAY_INTERFACE  CGI/1.1;

fastcgi_param SERVER_SOFTWARE   nginx/$nginx_version;

fastcgi_param REMOTE_ADDR        $remote_addr;

fastcgi_param REMOTE_PORT        $remote_port;

fastcgi_param SERVER_ADDR        $server_addr;

fastcgi_param SERVER_PORT        $server_port;

fastcgi_param SERVER_NAME        $server_name;

fastcgi_param REDIRECT_STATUS    200;

17.启动nginx:

/usr/local/nginx/sbin/nginx –t –c/usr/local/nginx/conf/nginx.conf

/usr/local/nginx/sbin/nginx

Ps –ef|grep nginx|grep –v ‘grep’

18.配置开机自动启动Nginx+PHP:

vim /etc/rc.local,末尾增加:

more /etc/rc.local |grep -v ‘^$‘|grep -v ‘#‘

touch /var/lock/subsys/local

/usr/local/nginx/sbin/nginx

/data0/mysql/3306/mysql start

/usr/local/php/sbin/php-fpm

19.优化Linux内核参数:

vim /etc/sysctl.conf,在末尾增加内容:

net.ipv4.tcp_max_syn_backlog = 65536

net.core.netdev_max_backlog = 32768

net.core.somaxconn = 32768

net.core.wmem_default = 8388608

net.core.rmem_default = 8388608

net.core.rmem_max = 16777216

net.core.wmem_max = 16777216

net.ipv4.tcp_timestamps = 0

net.ipv4.tcp_synack_retries = 2

net.ipv4.tcp_syn_retries = 2

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_mem = 94500000 915000000 927000000

net.ipv4.tcp_max_orphans = 3276800

net.ipv4.ip_local_port_range = 1024 65535

/sbin/sysctl -p

20.检查nginx配置文件:

/usr/local/nginx/sbin/nginx –t

21.创建index.php查看nginx解析PHP文件情况:

<?php

Phpinfo();

?>

22.检查nginx和php与mysql的连接情况:

vim mysql_test.php,内容如下:

<?php

$link=mysql_connect("localhost","admin","12345678");

if(!$link)

{

die(‘Could not connect: ‘.mysql_error());

}

else echo "Mysql test is successful!";

mysql_close($link);

?>

chmod 777 mysql_test.php

chown -R www:www mysql_test.php

23.nginx日志切割:

vim /usr/local/nginx/sbin/cut_nginx_log.sh

#! /bin/bash

#This script run at 00:00

#The Nginx logs path

logs_path="/data1/logs/"

mkdir -p ${logs_path}$(date -d "yesterday"+"%Y")/$(date -d "yesterday" +"%m")/

mv ${logs_path}access.log ${logs_path}$(date -d"yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date-d "yesterday" +"%Y%m%d").log

kill -USR1 `cat /usr/local/nginx/nginx/nginx.pid`

crontab –e

00 00 * * * /bin/bash/usr/local/nginx/sbin/cut_nginx_log.sh

/etc/init.d/crond restart

时间: 2024-10-14 00:52:59

Linux+Nginx Web Server+Mysql+PHP的相关文章

NGINX Web Server Nginx web 服务器

原文地址:http://nginx.com/resources/admin-guide/web-server/ NGINX Web Server Nginx web 服务器 This section describes: the most common configuration of a web server how to set up virtual servers and define locations for request processing how to use variable

NGINX Web Server Nginx web server

原文地址:http://nginx.com/resources/admin-guide/web-server/ NGINX Web Server Nginx web server This section describes: the most common configuration of a web server how to set up virtual servers and define locations for request processing how to use varia

How to Install Laravel with an Nginx Web Server on Ubuntu 14.04(Composer,laravel,nginx)

http://ubtutorials.com/tutorial/441/how-install-laravel-nginx-web-server-ubuntu-1404 https://github.com/huanghua581/laravel-getting-started/wiki/Ubuntu-14.04-%E4%B8%8A%E4%BD%BF%E7%94%A8-Nginx-%E9%83%A8%E7%BD%B2-Laravel http://www.ahlinux.com/ubuntu/2

Nginx学习笔记——搭建Linux +Nginx+PHP+Mariadb(MySql)开发环境

1.安装Nginx 源安装 本人安装环境是Deepin(Ubuntu的衍生版),所以最简单的方法就是执行 sudo apt-get install nginx 或者CentOS下: yum install nginx 编译安装 http://nginx.org/ 下载最新版1.9.5,支持HTTP/2模块,号称更快更安全,并且可以向下兼容,具体细节查看NGINX_HTTP2_White_Paper_v4.pdf 依赖关系:openssl-1.0.0s,pcre-8.36,zlib-1.2.8 分

Linux CentOS搭建JDK+Mysql+Tomcat+Nginx负载均衡环境 &nbsp; &nbsp; &nbsp;

本文使用了Tomcat+Nginx环境,主要起到负载均衡的作用,使用Tomcat处理jsp后台程序,使用Nginx处理静态页面. 准备工作(下载软件版本,请自行百度下载) 安装包放至:/usr/local/src 安装地址:/usr/local/软件名 1.apache-tomcat-6.0.48 2.mysql-5.5.54 3.nginx-1.6.3 4.cmake-2.8.8 5.pcre-8.40 6.jdk-8u11-linux-x64 7.openssl-1.1.0d(https使用

Install LEMP (Linux, Nginx, MySQL and PHP) Stack on Ubuntu Linux 14.04 LTS(转)

Install LEMP (Linux, Nginx, MySQL and PHP) Stack on Ubuntu Linux 14.04 LTS Nginx Installation Nginx is one of the robust web server in Linux world. Nginx is a free, open source, high performance HTTP server and reverse proxy, as weell as an IMAP/POP3

keepalived + nginx组建高可用负载平衡Web server集群

1 nginx负载均衡高可用 1.1 什么是负载均衡高可用 nginx作为负载均衡器,所有请求都到了nginx,可见nginx处于非常重点的位置,如果nginx服务器宕机后端web服务将无法提供服务,影响严重. 为了屏蔽负载均衡服务器的宕机,需要建立一个备份机.主服务器和备份机上都运行高可用(High Availability)监控程序,通过传送诸如"I am alive"这样的信息来监控对方的运行状况.当备份机不能在一定的时间内收到这样的信息时,它就接管主服务器的服务IP并继续提供负

Nginx安全配置标准(for web server)

一.目的 本标准是信息系统安全技术标准的一部分,主要目的是根据信息安全管理政策要求,为我司"Nginx web server"配置提供安全标准. 二.范围 本规范适用于我司所有Nginx web server. 三.内容 3.1 版本 使用较新的稳定版本 3.2 启动帐号 使用非root帐号启动 user www wwww; 或者 user nginx nginx; 3.3 日志记录 记录access log 3.4 预防php fastcgi文件名解析漏洞 如果nginx启用了php

centos6 LNMP的搭建(linux+nginx+mysql+php)

LNMP的搭建(linux+nginx+mysql+php) 简介 LNMP代表的就是:Linux系统下Nginx+MySQL+PHP网站服务器架构. Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统.代表版本有:debian.centos.ubuntu.fedora.gentoo等. Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器. Mysql是一个小型关系型数据库管理系统. PHP是一种在服务器端执行的嵌入HTML文档