V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
ssvodown
V2EX  ›  NGINX

LNMP 支持按国访问不同目录

  •  
  •   ssvodown · 2016-11-26 23:23:23 +08:00 · 3579 次点击
    这是一个创建于 2708 天前的主题,其中的信息可能已经有所发展或是发生改变。

    1 、安装 LNMP, 参考文档: http://www.luoxiao123.cn/centos-yum-lnmp.html

    https://maicong.me/t/188

    https://www.v2ex.com/t/258510

    yum install -y wget unzip && wget https://git.io/v2OPx -O LNMP.zip && unzip LNMP.zip && cd LNMP-master && bash lnmp.sh

    2 、升级 yum yum install gcc yum install zlib-devel

    3 、创建下载目录 mkdir -p /down

    4 、安装 MaxMind 的 GeoIP 库 cd /down wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz tar -zxvf GeoIP.tar.gz cd GeoIP-1.4.8 ./configure make && make install

    5 、刚才安装的库自动安装到 /usr/local/lib 下,所以这个目录需要加到动态链接配置里面以便运行相关程序的时候能自动绑定到这个 GeoIP 库: echo '/usr/local/lib' > /etc/ld.so.conf.d/geoip.conf ldconfig

    6 、下载 IP 数据库 cd /down wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz gunzip GeoIP.dat.gz mv /down/GeoIP.dat /etc/nginx/GeoIP.dat

    7 、让 Nginx 支持 GEOIP ps -ef | grep nginx pkill -9 nginx yum -y install openssl openssl-devel yum install pcre yum -y install libxml2-devel libxslt-devel yum install gd-devel yum install perl perl-devel perl-ExtUtils-Embed cd /down

    nginx -V (查看原来编译时都带了哪些参数) wget http://nginx.org/download/nginx-1.10.2.tar.gz (下载地址: http://nginx.org/en/download.html ) tar zxvf nginx-1.10.2.tar.gz cd nginx-1.10.2/


    ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --with-http_geoip_module


    make cp /usr/sbin/nginx /usr/sbin/nginx.bak cp ./objs/nginx /usr/sbin/

    启动 nginx /usr/sbin/nginx 或 systemctl start nginx.service /usr/sbin/nginx -s reload (重启)

    8 、配置 Nginx

    vi /etc/nginx/nginx.conf

    修改以下内容: http { ...


    geoip_country /etc/nginx/GeoIP.dat;

    fastcgi_param GEOIP_COUNTRY_CODE $geoip_country_code;

    fastcgi_param GEOIP_COUNTRY_CODE3 $geoip_country_code3;

    fastcgi_param GEOIP_COUNTRY_NAME $geoip_country_name;


    ... }

    vi /etc/nginx/conf.d/nginx-index.conf

    server { listen 80; server_name localhost;

    location / {
    	
    

            	if ($geoip_country_code = JP) {
    	       root  /home/wwwroot/index$subdomain;
    	}
    	 if ($geoip_country_code = CN) {
    	       root  /home/wwwroot/index$subdomain;
    	}
    

    }
    

    }

    /usr/sbin/nginx -s reload (重启)

    iptables -I INPUT -p tcp --dport 80 -j ACCEPT (开放端口)

    7 、配置网站

    添加一个标识为 mysite ,域名为 mysite.com 的站点 service vhost add domain domain.com,www.domain.com index.html,index.htm,index.php nomal.conf on

    8 、修改 mysql 密码 SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');

    9 、配置 phpMyAdmin cp /home/wwwroot/index/phpMyAdmin/libraries/config.default.php /home/wwwroot/index/phpMyAdmin/libraries/config.default.php_bak vi /home/wwwroot/index/phpMyAdmin/libraries/config.default.php

    $cfg['Servers'][$i]['user'] : mysql 数据库用户名 $cfg['Servers'][$i]['password'] : mysql 数据库密码

    $cfg['Servers'][$i]['host'] = 'localhost'; 修改为 $cfg['Servers'][$i]['host'] = '127.0.0.1';

    在 phpmyadmin 新建用户账户: user name :name hostname :127.0.0.1 pass : 123456

    10 、上传文件: 软件名称: SSHSecureShellClient

    11 、安全配置

    服务器禁止 ping cp /etc/rc.d/rc.local /etc/rc.d/rc.localbak vi /etc/rc.d/rc.local 在文件末尾增加下面这一行 echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all   参数 0 表示允许 1 表示禁止

    更改 SSH 端口 netstat -lntp systemctl status firewall 查看 firewall 服务状态 firewall-cmd --state 查看 firewall 的状态 firewall-cmd --list-all 查看防火墙规则

    cp /etc/ssh/sshd_config /etc/ssh/sshd_config_bak vi /etc/ssh/sshd_config 先将 Port 22 前面的 号去掉,并另起一行 添加: Port 9999 firewall-cmd --permanent --zone=public --add-port=9999/tcp firewall-cmd --permanent --zone=public --add-port=8088/tcp firewall-cmd --permanent --zone=public --remove-port=22/tcp systemctl restart sshd.service firewall-cmd --reload service firewalld restart 测试 9999 可以连接后 vi /etc/ssh/sshd_config 将 Port 22 前面的 号加上


    启动标识为 domain 的站点 service vhost start domain

    停止标识为 domain 的站点 service vhost stop domain

    编辑标识为 domain 的站点 service vhost edit domain

    删除标识为 domain 的站点 service vhost del domain

    列出所有站点 service vhost list


    3 、服务管理

    启动 MySQL systemctl start mysqld.service

    停止 MySQL systemctl stop mysqld.service

    重启 MySQL systemctl restart mysqld.service

    启动 MariaDB systemctl start mariadb.service

    停止 MariaDB systemctl stop mariadb.service

    重启 MariaDB systemctl restart mariadb.service

    启动 PHP systemctl start php-fpm.service

    停止 PHP systemctl stop php-fpm.service

    重启 PHP systemctl restart php-fpm.service

    启动 Nginx systemctl start nginx.service

    停止 Nginx systemctl stop nginx.service

    重启 Nginx systemctl restart nginx.service

    启动 SVN systemctl start svnserve.service

    停止 SVN systemctl stop svnserve.service

    重启 SVN systemctl restart svnserve.service


    9 条回复    2016-11-28 06:05:46 +08:00
    Showfom
        1
    Showfom  
       2016-11-27 09:48:36 +08:00 via iPhone
    只看到了满屏的编译........醉了 有什么事是 nginx-extras 不能做的?
    ssvodown
        2
    ssvodown  
    OP
       2016-11-27 13:02:43 +08:00
    @Showfom 初学 nginx ,见谅! nginx-extras 是什么?网上找不到详细的资料,求教
    bobylive
        3
    bobylive  
       2016-11-27 14:56:23 +08:00 via Android
    @Showfom 我用的 full 也是自带了 GEOIP 了
    ssvodown
        4
    ssvodown  
    OP
       2016-11-27 20:43:09 +08:00
    @bobylive full 是什么? lnmp.org 的一键安装包吗?好像没有自带 GEOIP 吧
    billlee
        5
    billlee  
       2016-11-27 22:24:53 +08:00
    @ssvodown aptitude install nginx-full
    bobylive
        6
    bobylive  
       2016-11-27 23:16:46 +08:00 via Android
    @ssvodown apt-get install nginx-full
    Showfom
        7
    Showfom  
       2016-11-28 01:18:38 +08:00 via iPhone
    @bobylive 现在新版本 mods 都可以自己选 Available 了 233
    bobylive
        8
    bobylive  
       2016-11-28 02:55:05 +08:00 via Android
    @Showfom 应该是 1.9.11 之后开始的,和 PHP-FPM 一样可以独立安装 Package
    Showfom
        9
    Showfom  
       2016-11-28 06:05:46 +08:00
    @bobylive 稳定版的话 1.10 好像才有 之前我没见到过来着 偶数 stable 奇数 mainline
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2698 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 11:42 · PVG 19:42 · LAX 04:42 · JFK 07:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.