标签 web 下的文章

killall nginx后无法再启动

某次killall nginx后,nginx服务无法再启动。

ps -ef |grep nginx
root     63703  2548  0 14:34 pts/0    00:00:00 grep --color=auto nginx

查看端口,80端口并无其他服务占用:

netstat -lnpt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      3181/mysqld
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2097/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2437/master
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      62906/php-fpm: mast
tcp6       0      0 :::22                   :::*                    LISTEN      2097/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      2437/master

- 阅读剩余部分 -

lanmp一键安装脚本

一、要求

  • 系统:CentOS 7+
  • 用户:root

二、使用

1. 自定义安装路径

获取脚本

git clone https://github.com/a1711hw/lanmp.git
cd lanmp.sh

# 配置执行权限
chmod +x lanmp.sh

可以自行修改lanmp.conf配置文件,定义安装路径:

# lamp and lnmp directory configuration.

# mysql
mysql=/usr/local/mysql
mysql_data=/data/mysql

# apache
apache=/usr/local/apache24

# php version
php=/usr/local/php

# nginx
nginx=/usr/local/nginx

# php-fpm
php_fpm=/usr/local/php-fpm

# website directory
web_data=/data/www

- 阅读剩余部分 -

Apache httpd访问日志

Apache的安装之后,服务器一运行就会有两个日志文件生成。这两个文件是access_log和error_log,这些文件可以在/usr/local/apache/logs下找到。

1. 配置访问日志

修改 httpd 的主配置文件,将以下配置前面的注释去掉:

vim /usr/local/apache24/conf/httpd.conf

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

以上配置参数介绍,这些参数可按需增删,一般默认即可。

%h:远程主机。
%l:远程登录名字(来自identd,如提供的话)。
%u:远程用户(来自auth;如果返回状态(%s)是401则可能是伪造的)
%t:以公共日志时间格式表示的时间(或称为标准英文格式)。

- 阅读剩余部分 -

Nginx访问日志

1. 日志配置

在Nginx的配置文件中:

……省略一些配置……

# 这个是Nginx的日志,已经定义了日志文件的存放路径
error_log /usr/local/nginx/logs/nginx_error.log crit;
……省略一些配置……

http {
……省略一些配置……

    # 这个是网站日志的格式,可以自行调节先后顺序进行排版
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    ' $host "$request_uri" $status'
    ' "$http_referer" "$http_user_agent"';

……省略一些配置……
}

- 阅读剩余部分 -

Nginx访问控制

1. 用户认证

用户认证用来控制不想让其它用户访问的地址,在虚拟主机配置文件中这样定义:

server
{
    listen 80;
    server_name example.com;
    index index.html index.htm index.php;
    root /data/www/example;

    location  /{
        auth_basic              "Auth";
        auth_basic_user_file   /usr/local/nginx/conf/htpasswd;
    }
}

然后使用Apache的密码工具生成用户密码文件:

htpasswd -c /usr/local/nginx/conf/htpasswd username

- 阅读剩余部分 -

Nginx简单配置

一、Nginx虚拟主机

在Nginx中,我们可以使用多个配置文件来更加人性化的管理不同的站点,首先需要在Nginx的配置文件,nginx.conf中http部分加入这样一行:

    include vhost/*.conf

在当前目录下创建vhost目录,然后在vhost目录下创建一个.conf配置文件,简单的配置大致如下:

server
{
    listen 80 default_server;
    server_name default.com;
    index index.html index.htm index.php;
    root /data/www/default;
}

default_server:这个标记表示默认虚拟主机。

- 阅读剩余部分 -