2019年nginx安装手册
nginx下载安装
nginx下载安装
环境:centos 7
1:下载Nginx
访问Nginx官⽹,选择⼀个版本获取下载链接,如下:
使⽤wget 命令下载Nginx,如下:
wget /download/nginx-1.16.0.tar.gz
2:解压Nginx
使⽤tar -zxvf 命令解压Nginx安装包,如下:
3:安装Nginx
进⼊到解压后的Nginx⽬录,使⽤ ./configure --prefix=/usr/local/nginx 命令指定nginx的安装位置,我们指定了/usr/local/nginx这个⽬录
执⾏过程中如果出现如下错误:
则需要安装prce 库,使⽤yum installl pcre 命令进⾏安装
这⾥仅仅安装pcre是不⾏的,⼀样会提⽰需要pcre库,这⾥
还要安装pcre-devel,我们继续执⾏yum install pcre-devel 命令进⾏安装
我们再次执⾏./configure --prefix=/usr/local/nginx
会出现如下错误:
提⽰我们安装zlib,我们继续执⾏yum install zlib命令安装zlib,⼀样我们也要安装zlib-devel 。
安装完毕后,重新执⾏./configure --prefix=/usr/local/nginx命令,如下:
说明我们已经ok
接下来,我们使⽤make && make install 命令进⾏编译安装nginx
进⼊到/usr/local⽬录下我们可以看到多了nginx⽬录,说明我们已经安装成功。
Nginx配置手册(64)
扩展文件存放目录:/usr/lib64/extensions/no-d2文件拥有者,拥有组
Mysql用户
/data/mysql/
/usr/local/webserver/mysql
/data/logs
/data/htdocs/html
3.3Php编译参数详解18
3.4Nginx编译参数详解18
3.5扩展库详解22
—、r 4
1
1.1配置说明
本配置手册仅限于Nginx-0.8.54 , Oraclell , Mysql5.1.49 , PHP-5.3.2以及32位操作系统Cent0S_5.5。
1.1.1有关文件目录
安装程序源代码存放目录:/usr/local/src
软件安装目录:
1)Nginx安装目录:/usr/local/webserver/nginx
2)PHP安装目录:/usr/local/webserver/php
3)Mysql安装目录:/usr/local/webserver/mysql
网站程序存放目录:/data/htdocs/html
Mysql数据库存放目录:/data/mysql/3306/data/
6)libiconv-1.13.1.tar.gz
7)libmcrypt-2.5.8
8)mcrypt-2.6.8.tar.gz
9)memcached-1.4.5.tar.gz
10)memcache-2.2.5.tgz
11)mhash-0.9.9.9.tar.gz
12)mysql-5.1.49.tar.gz
13)nginx-0.8.54.tar.gz
14)oracle-instantclient11.2-basic-11.2.0.1.0-1.x86_64.rpm
Nginx安装及配置文件解释
Nginx安装及配置⽂件解释安装nginx,还是在mac上⾯⽤brew⽐较⽅便。
⾸先,brew install nginx,提⽰改权限sudo chown -R $(whoami) /usr/local然后brew install nginx,下载⼀些包始终太慢。
然后查看brew --cache,发现缓存在/Users/baidu/Library/Caches/Homebrew在下载慢的包,浏览器下载好放在这个⽬录,然后再次 brew install nginx 成功。
启动命令:brew services start nginxWelcome to nginx!If you see this page, the nginx web server is successfully installed and working. Further configuration is required.For online documentation and support please refer to .Commercial support is available at .Thank you for using nginx.查看版本:$ nginx -vnginx version: nginx/1.10.1默认的nginx配置⽂件是在/usr/local/etc/nginx/nginx.confroot⽬录是在/usr/local/Cellar/nginx/1.10.1/html本⾝Nginx启动过程中的⽇志是在:/usr/local/var/log/nginx/error.logaccess.log在Nginx的配置⽂件中打开⽇志后:error_log logs/error.log;对应的是:/usr/local/Cellar/nginx/1.10.1/logs/Mac默认的Php和php-fpm安装了:$ which php/usr/bin/php$ which php-fpm/usr/sbin/php-fpm$ ls /etc/phpphp-fpm.conf.default php.ini.default$ php -vPHP 5.5.30 (cli) (built: Oct 23 2015 17:21:45)启动php-fpm前要准备好配置⽂件:sudo cp /private/etc/php-fpm.conf.default /private/etc/php-fpm.conf然后 php-fpm , 仍然报下⾯的错$ php-fpm[04-Oct-2016 16:46:40] ERROR: failed to open error_log (/usr/var/log/php-fpm.log): No such file or directory (2)需要sudo vi /private/etc/php-fpm.conf改两个地⽅:error_log = /usr/local/var/log/php-fpm.logpid = /usr/local/var/run/php-fpm.pid然后php-fpmphp⽰例⽂件<?phpecho "hi";>然后 php -f hi.php可以运⾏然后我尝试把端⼝设成80,但是在这个error log:/usr/local/var/log/nginx/error.log 报错:2016/10/04 17:00:12 [emerg] 26905#0: bind() to 0.0.0.0:80 failed (13: Permission denied)所以只好改成7080然后发现php⽂件始终是在浏览器页⾯报这个错:"File not found",然后在后台⽇志报这个错:2016/10/04 17:01:39 [error] 27052#0: *1 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1:7080"在⽹上搜索之后,需要把/usr/local/etc/nginx/nginx.conf ⾥⾯ fastcgi_param⾥⾯的 /scripts$fastcgi_script_name; 改成 $document_root$fastcgi_script_name; 重启之后即可。
Nginx服务器的安装和卸载
Nginx服务器的安装和卸载Nginx的安装Windows版本的安装Nginx的Windows版本安装⽐较简单。
下载完安装包之后解压缩即可使⽤。
如果你需要在命令⾏窗⼝执⾏nginx命令,你还需要将nginx的解压⽬录加⼊环境变量。
#Windows平台下相关操作#step1:⾸先cd到nginx的安装⽬录,最好不要将安装⽬录加到环境变量,会出现不必要的问题。
(有条件最好在Linux环境下操作)start nginx 或者 nginx.exe //启动nginxnginx.exe -s stop //⽴即停⽌nginx服务nginx.exe -s quit //有序停⽌nginxnginx.exe -s reload //修改配置后加载新的配置nginx.exe -s reopenLinux版本的安装Linux版本的Nginx推荐使⽤源代码安装。
1. 环境准备为了编译Nginx源代码,我们需要标准的GCC编译器。
GCC的全称为GNUCompiler Collection,其由GNU开发,并以GPL及LGPL许可证发⾏,是⾃由的类UNIX及苹果电脑Mac OS X操作系统的标准编译器。
因为GCC原本只能处理C语⾔,所以原名为GNU C语⾔编译器,后来得到快速扩展,可处理C++、Fortran、Pascal、Objective-C、Java以及Ada等其他语⾔。
除此之外,我们还需要Automake⼯具,以完成⾃动创建Makefile的⼯作。
由于Nginx的⼀些模块还需要依赖其他第三⽅库,通常有pcre库(⽀持rewrite模块)、zlib库(⽀持gzip模块)和openssl库(⽀持ssl模块)等。
所以在编译Nginx源代码前还需要安装这些这些库。
#gcc安装yum -y install gcc-c++#pcre安装yum -y install pcre pcre-devel#zlib安装yum -y install zlib zlib-devel#OpenSSL安装yum -y install openssl openssl-devel前⾯3个就不说了,很多软件都会依赖到的包。
Nginx安装
Nginx 服务器的安装及配置文件详解如下:一、安装依赖的程序1. gzip module requires zlib library(/)2. rewrite module requires pcre library (/projects/pcre/files/)3. ssl support requires openssl library (/)根据实际情况安装时确定,我在安装的时候,只缺少了pcre这个库/projects/pcre/files/,其他没遇到,如果需要也可以下载,就到网上搜索二、安装首先上传到pcre zip 文件,解压后,到时候ngnix需要指定解压的路径,加载所需要的文件./configuremakemake install默认安装的路径是/usr/local/nginx更多的安装配置./configure --prefix=/home/nginx--with-openssl=/home/nginx/include (启用ssl)--with-pcre=/home/nginx/pcre-8.12 (启用正规表达式这里可能是源代码的路径)--with-http_stub_status_module (安装可以查看nginx状态的程序)--with-http_memcached_module (启用memcache缓存)--with-http_rewrite_module (启用支持url重写)三、启动及重启启动:nginx重启:kill -HUP `cat /usr/local/nginx/logs/nginx.pid`测试配置文件:nginx -t简单吧,安装,启动都比较方便。
四、配件文件http服务配置文件:复制代码#运行用户user nobody nobody;#启动进程worker_processes 5;#全局错误日志及PID文件error_log logs/error.log notice;pid logs/nginx.pid;#工作模式及连接数上限events {#工作模式有:select(标准模式),poll(标准模式),kqueue(高效模式,适用FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 and MacOS X),#epoll(高效模式,本例用的。
nginx安装+配置文档
1、nginx安装步骤1.1 下载介质NgInx 部署之前,首先根据项目的需要选择需要安装的组件,实际环境一般会考虑需要支持gzip 压缩和rewrite 模块。
所以安装的第一步是下载Ngix 及Ngix 的相关组件。
Nginx 本身下载地址:/en/download.html建议下载最新版本介质,目前最新的是:0.9.6gzip 压缩依赖库:zlib下载地址:/我下载的版本是:Version 1.2.5Rewrite 模块的正则表达式依赖库:pcrepcre 库简称:Perl 兼容正则表达式(Perl Compatible Regular Expressions)库。
关于正则表达式的写法可以参考附件《perlre - perldoc_perl_org.mht》下载地址:/我下载的版本是:pcre-8.021.2 编译部署介质1.2.1 部署zlib 库执行Linux 命令解压缩后编译安装:tar -zxvf zlib-1.2.5.tar.gz./configure --prefix=路径,需要装到那个路径下根据需要makemake install默认安装到/usr/local/lib 下即可。
安装完成后可以ls -l /usr/local/lib/libz.so 查询是否安装成功,安装成功后,通过ls 可以提示文件已经存在。
1.2.2 部署pcre 库执行Linux 命令解压缩后编译安装:tar -zxvf pcre-8.02.tar.gz./configure --prefix=路径,需要装到那个路径下根据需要makemake install默认安装到/usr/local/lib 下即可,安装完成后可以ls -l /usr/local/lib/libpcre.so查询是否安装成功1.2.3 部署nginx1. 解压缩介质:tar -zxvf nginx-0.9.6.tar.gz2. 编译安装方法一:./configure --prefix=/usr/local/nginx(安装nginx的位置)--with-http_stub_status_module --without-poll_module --without-select_module --with-http_ssl_module --with-http_realip_module --with-http_perl_module --with-pcre=/opt/pcre-8.32(安装nginx 所依赖的pcre源码目录位置) --with-pcre-jit#make && make install安装方法二:@安装nginx /usr/local/nginx 本机上nginx源码放置的目录位置# wget /download/nginx-1.0.10.tar.gz# tar zxvf nginx-1.0.10.tar.gz# cd nginx-1.0.10# ./configure --user=nobody --group=nobody --prefix=/usr/local/webserver/nginx (nginx安装的目录)--with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/webserver/pcre (安装nginx需要的pcre源码目录位置)# vi objs/Makefile查找configure --disable-shared,删除./configure --disable-shared, 保存(根据需要,若安装过程中包这个错的话,删掉它)#make && make install需要关注编译的日志l checking for epoll ... found 代表找到了高效的poll 模式l checking for PCRE library ... found 代表找到了pcre 库l checking for zlib library ... found 代表找到了zlib 库l 如果后面需要用到状态监控,需要加上-with-http_stub_status_module3. 用make 来安装:makemake install二、配置nginx.confuser root; #设置用户设置成root 用户赋给他最大权限worker_processes 1; #工作进程,根据硬件调整,根据机器CPU可以配置多个进程#error_log logs/error.log; #错误日志#error_log logs/error.log notice;error_log /var/log/nginx/nginx_error.log crit;pid /opt/nginx/nginx.pid; #pid文件位置events {use epoll; #指定事件响应模式为为高效的poll 模式worker_connections 51200; #工作进程的最大连接数量,根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就可以}http {include mime.types;default_type application/octet-stream;#default_type text/html; #根据实际情况而定用哪种格式#log_format main '$remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" '# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;#upstream的负载均衡,weight是权重,可以根据机器配置定义权重。
Nginx安装文档
Nginx安装文档注:安装版本centos6内核版本2.6.32-279.el6.i6861安装准备1.1安装依赖yum –y install gcc gcc-c++ autoconf automake bzip2-devel ncurses-developenssl-devel libtool* zlib-devel libxml-devel libjpeg-devel ligpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel curl curl-devel pam-devel e2fsprogs-devel krb5-devel libidn libidn-devel1.2Pcre安装●可利用yum –y install pcre-devel完成安装●源码安装⏹访问/获取最新版本PCRE⏹编译安装PCRE1.3Nginx版本获取通过/en/download.html获取最新版本2安装nginx注:其中参数 --with-http_stub_status_module 是为了启用nginx 的NginxStatus 功能,用来监控Nginx 的当前状态。
如提示找不到pcre,可添加--with-pcre=<path>指定路径安装成功后/opt/nginx 目录下有四个子目录分别是:conf、html、logs、sbin 。
其中Nginx 的配置文件存放于conf/nginx.conf,Nginx 只有一个程序文件位于sbin 目录下的nginx 文件。
确保系统的80 端口没被其他程序占用,运行sbin/nginx 命令来启动Nginx,打开浏览器访问此机器的IP,如果浏览器出现Welcome to nginx! 则表示Nginx 已经安装并运行成功。
nginx从安装到配置详细说明(安装,安全配置,防盗链,动静分离,配置
nginx从安装到配置详细说明(安装,安全配置,防盗链,动静分离,配置 HTTPS,性能优化)⼀、服务器基础配置远程链接服务器ssh ⽤户名@公⽹ip默认的⽤户名是root,假如公⽹ ip 是 a.b.c.d, 那链接命名就是ssh root@a.b.c.d下载安装基础库yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automakeyum -y install wget httpd-tools vim关闭 iptables查看iptables规则iptables -L或iptables -t nat -L关闭 iptables 规则iptables -F或iptables -t nat -F关闭 SELinux查看是否打开getenforce关闭setenforce 0⼆、Nginx 简介及安装Nginx 是⼀个开源且⾼性能、⾼可靠的 HTTP 中间件、代理服务。
安装Nginx打开官⽹To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents:[nginx]name=nginx repobaseurl=/packages/OS/OSRELEASE/$basearch/gpgcheck=0enabled=1Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “6” or “7”, for 6.x or 7.x versions, respectively.三、安装⽬录及配置讲解3.1 安装⽬录讲解查看nginx的所有安装⽬录rpm -ql nginx然后得到如下配置[root@ ~]# rpm -ql nginxnginx⽇志轮转,⽤于logrotate服务的⽇志切割/etc/logrotate.d/nginxnginx主配置⽂件/etc/nginx/nginx.conf/etc/nginx/etc/nginx/conf.d/etc/nginx/conf.d/default.confcgi配置相关,fastcgi配置/etc/nginx/fastcgi_params/etc/nginx/scgi_params/etc/nginx/uwsgi_params编码转换映射转化⽂件/etc/nginx/koi-utf/etc/nginx/koi-win/etc/nginx/win-utf设置http协议的 Content-Type 与扩展名对应关系/etc/nginx/mime.types⽤于配置出系统守护进程管理器管理⽅式/etc/sysconfig/nginx/etc/sysconfig/nginx-debug/usr/lib/systemd/system/nginx-debug.service/usr/lib/systemd/system/nginx.servicenginx模块⽬录/etc/nginx/modules/usr/lib64/nginx/modules/usr/lib64/nginx/usr/libexec/initscripts/legacy-actions/nginx/usr/libexec/initscripts/legacy-actions/nginx/check-reload/usr/libexec/initscripts/legacy-actions/nginx/upgradenginx服务的启动管理的终端命令/usr/sbin/nginx/usr/sbin/nginx-debugnginx的⼿册和帮助⽂件/usr/share/doc/nginx-1.14.0/usr/share/doc/nginx-1.14.0/COPYRIGHT/usr/share/man/man8/nginx.8.gz/usr/share/nginx/usr/share/nginx/html/usr/share/nginx/html/50x.html/usr/share/nginx/html/index.htmlnginx 的缓存⽬录/var/cache/nginxnginx⽇志⽬录/var/log/nginx3.2 安装编译参数命令nginx -V查看所有编译参数3.3 Nginx 默认配置语法参数说明user设置nginx服务的系统使⽤⽤户worker_processes⼯作进程数(⼀般与服务器核数保持⼀致)rror_log nginx的错误⽇志pid nginx服务启动时候pidevents -> worker_connections每个进程允许最⼤连接数events -> use⼯作进程数nginx 的默认配置⽂件⽂件路径/etc/nginx/conf.d/default.confserver {listen 80;server_name localhost;#charset koi8-r;#access_log /var/log/nginx/host.access.log main;location / {root /usr/share/nginx/html;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root /usr/share/nginx/html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}可以去/usr/share/nginx/html/index.html修改默认的展⽰页⾯,也可以去/usr/share/nginx/html/50x.html修改错误页⾯。
nginx安装及简单使用
nginx安装及简单使⽤Nginx("engine x")是⼀款是由俄罗斯的程序设计师Igor Sysoev所开发⾼性能的 Web和反向代理服务器,也是⼀个 IMAP/POP3/SMTP 代理服务器。
在⾼连接并发的情况下,Nginx是Apache服务器不错的替代品。
安装 Nginxnginx常⽤命令start nginx #启动nginxnginx -s quit #优雅停⽌nginx,有连接时会等连接请求完成再杀死worker进程nginx -s reload #优雅重启,并重新载⼊配置⽂件nginx.confnginx -s reopen # 重启 Nginx 重新打开⽇志⽂件,⼀般⽤于切割⽇志nginx -v #查看版本nginx -t #检查nginx的配置⽂件nginx -h #查看帮助信息nginx -V #详细版本信息,包括编译参数nginx -c filename #指定配置⽂件1.windows下直接安装(如有IIS,要关闭IIS),使⽤cmd找到安装路径,执⾏start nginx,通过浏览器访问localhost可以显⽰nginx主页2.配置:找到conf/nginx.conf,参考以下内容作修改,修改完后使⽤cmd 执⾏nginx -s reload重启nginx即可# 1.下载安装后打开nginx安装⽬录,找到conf/nginx.conf,使⽤⽂本/编辑器打开#user nobody;worker_processes 1; #设置值和CPU核⼼数⼀致#error_log logs/error.log; #⽇志位置和⽇志级别#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" '# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server_names_hash_bucket_size 64;proxy_buffer_size 128k; # default: 4k|8kproxy_buffering on; # default: onproxy_buffers 64 64k; # default: 8 4k|8kproxy_busy_buffers_size 256k; # default: 8k|16kproxy_max_temp_file_size 1024m; # default: 1024mproxy_temp_file_write_size 256k; # default: 8k|16kproxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#下⾯是server虚拟主机的配置server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.htmlerror_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}server {listen 80;server_name ******.com; #*修改为域名return 301 http://www.******.com$request_uri; #*修改为域名}# 解析server {listen 80; #监听端⼝server_name ; #*修改为域名 #域名# index index.html index.htm index.php; #站点⽬录下默认访问的⽂件 /nginx/html/index# root /usr/local/webserver/nginx/html;#站点⽬录location / { //⽂件路由root path; #⽂件路径⽰例:C:/testtry_files $uri $uri/ /index.html;}location /view/ {root path; #⽂件路径⽰例:C:/testrewrite .* /index.html break;}}}Nginx默认的配置⽂件主要有 main、events、http、server、location 五个块组成。
Nginx编译安装与简单配置手册
目录Nginx编译安装与简单负载均衡配置 (1)Nginx安装 (1)准备的软件 (1)安装nginx-1.4.1.tar.gz (2)可能的错误 (3)配置负载均衡 (4)附录一Nginx常见指令 (5)启动Nginx (5)停止Nginx (5)Nginx 重载配置 (5)检查配置文件是否正确 (5)显示帮助信息 (6)附录二nginx.conf配置文件详解 (6)Nginx编译安装与简单负载均衡配置Nginx安装准备的软件nginx-1.4.1.tar.gz (以nginx-1.4.1为例)下载地址:/en/download.html其中包含开发版和稳定版,到目前为止稳定版本最高版本号为1.4.1nginx-sticky-module-1.1.tar.gz(以nginx-sticky-module-1.1为例)下载地址:/p/nginx-sticky-module/downloads/list安装nginx-1.4.1.tar.gz解压nginx-1.4.1.tar.gz(解压到/root下)解压nginx-sticky-module-1.1.tar.gz(解压到/root下)检查安装环境并配置切换到nginx-1.4.1目录下具体执行命令如下注:nginx-1.4.1为解压nginx-1.4.1.tar.gz后的根目录。
/root/nginx-sticky-module-1.1为解压nginx-sticky-module-1.1.tar.gz后的根目录。
编译如编译过程中出现错误可参见下面可能出现的错误。
执行该处命令有可能会因为缺少操作系统类库而导致编译失败,15s现场遇到过,当时15s联系的中标系统人员带着系统盘过去解决的。
安装启动nginx进入Nginx默认安装目录/usr/local/nginx/sbin目录.验证安装是否成功在浏览器地输入http://127.0.0.1 如果出现以下类似页面代表安装成功常用操作命令见附录一。
nginx部署手册
部署手册1环境介绍1.1路径规划程序安装包路径:/home/gzyhpay/setupNginx部署路径:/home/gzyhpay/nginxWeb资源部署路径:/home/gzyhpay/webapp/应用名Web日志路径:/home/gzyhpay/logs/需ip访问的应用的web日志路径:/home/gzyhpay/weblogs/iprequestJdk路径:/home/gzyhpay/jdkJboss路径:/home/gzyhpay/jboss/Jboss系统日志路径:/home/gzyhpay/jboss/standalone/log应用程序发布路径:/home/gzyhpay/jboss/standalone/deployments银行认证凭证路径:/home/gzyhpay/work/bankconf应用日志路径:/home/gzyhpay/work/logs/应用名应用文件下载缓存路径:/home/gzyhpay/work/download/应用名应用文件上传缓存路径:/home/gzyhpay/work/upload/应用名2新建服务器的软件准备2.1Web服务器软件部署Web服务器采用nginx中间件。
要部署nginx中间件,需先确保web服务器安装了g++或c++编译环境。
没有g++或c++的操作系统请找安装盘安装。
2.1.1nginx安装包/home/gzyhpay/setup/nginx2.1.2安装执行setupNGINX.sh脚本直至完成安装。
程序安装后,会自动在当前用户目录下建立nginx目录,如home/gzyhpay/nginx。
2.1.3基本配置fastcgi.conf proxy_conf.conf reload.sh testConfig.sh mime.types以下以$NGINXHOME代表nginx所在目录,目前路径为:/home/gzyhpay/nginxtestConfig.sh脚本为配置文件检测脚本,建议放在$NGINXHOME。
Nginx安装配置说明
Nginx简要安装配置说明一.N ginx简介Nginx是一款高性能的HTTP和反向代理服务器软件,可以运行在UNIX、GNU/Linux、BSD、Mac OS X、Solaris 以及Microsoft Windows等操作系统中。
其优点是占用系统资源少,支持大并发连接(官方声称最大支持5万并发连接响应而只占2.5M内存);因其部署简单,配置灵活、高效、稳定的特点已被广泛应用于各大型网站架构中。
二.安装1).安装所需环境gcc-c++ 、openssl-devel 、pcre-devel 、zlib-devel 、libtool2).安装pcre,使Nginx支持rewrite模块tar zxvf pcre-8.30.tar.gzcd pcre-8.30make && make install3).安装Nginxtar zxvf nginx-1.2.3.tar.gzcd nginx-1.2.3./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_gzip_static_module --with-http_ssl_module编译时可根据实际需要进行编译所需要的模块,用./configure –help查看可编译的模块三.常用命令1).检查配置文件是否正确/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf2).启动/usr/local/nginx/sbin/nginx3). 平滑重启/usr/local/nginx/sbin/nginx -s reload四.配置1).配置文件结构Nginx的配置文件是一个纯文本文件,它一般位于Nginx安装目录的conf目录下,整个配置文件是以block的形式组织的。
每个block一般以一个大括号“{}”来表示,block可以分为几个层次,整个配置文件中main指令位于最高层,在main层下面可以有Events、HTTP 等层级,而在HTTP层中又包含有server层,即server block,server block中又可分为location 层,并且一个server block中可以包含多个location block。
Nginx 用户指南说明书
Table of ContentsAbout1 Chapter 1: Getting started with nginx2 Remarks2 Versions2 Examples2 Installation and setup2 Nginx installation on Debian and Debian-based distros like Ubuntu3 Restart NGINX3 Ubuntu example3 Reload NGINX configuration file3 Ubuntu 14.04 example4 Ubuntu 16.04 example4 Shutdown NGINX4 Nginx inside4 Test if your changes in nginx.config are valid5 Chapter 2: Logging6 Examples6 Basic example6 Syntax6 Reopen log files6 Avoid logging for favicon.ico and robots.txt6 Chapter 3: Nginx Configurations7 Examples7 Configuration File’s Structure7 Simple Directives7 Block Directive7 Context7 Comment7 Test NGINX configuration file7 Specify configuration file to load8config changes without restart8 Logging to Syslog, incl. mapping of HTTP-Codes to Syslog severities.8 Limit request methods9 Chapter 4: nginx reverse proxy10 Examples10 simple reverse proxy10 Chapter 5: Useful Redirects11 Examples11 HTTPS Redirect11 Redirect requests to another server11 Mobile Site Redirection11 HTTP location on HTTPS server12 Disallow Requests Based on Host or Country Code12 Chapter 6: Using nginx to provide clean browser URLs14 Examples14 Redirect vs reverse proxy14 Chapter 7: Wordpress blog integration with rails application using nginx16 Examples16 nginx server block16 Credits18AboutYou can share this PDF with anyone you feel could benefit from it, downloaded the latest version from: nginxIt is an unofficial and free nginx ebook created for educational purposes. All the content is extracted from Stack Overflow Documentation, which is written by many hardworking individuals at Stack Overflow. It is neither affiliated with Stack Overflow nor official nginx.The content is released under Creative Commons BY-SA, and the list of contributors to each chapter are provided in the credits section at the end of this book. Images may be copyright of their respective owners unless otherwise specified. All trademarks and registered trademarks are the property of their respective company owners.Use the content presented in this book at your own risk; it is not guaranteed to be correct nor accurate, please send your feedback and corrections to ********************Chapter 1: Getting started with nginxRemarksNGINX is pronounced like "engine x" and is commonly used as a high performance server for protocols HTTP, HTTPS, SMTP, POP3 and IMAP. It can be used as a reverse proxy server, HTTP cache or load balancing.It is an open source project with source available here.VersionsExamplesInstallation and setupNginx is a Web server used to serve HTTP requests over the Internet.Nginx is available on Linux, Windows and other OSes as direct download, and can also be built from source. For detailed instructions see Nginx official reference.ubuntu/debiannginx stable version is available in official repo, it can be installed usingsudo apt-get install nginxIt will install and configure system startup files, but if you need latest version, you may need to add official ppa.sudo add-apt-repository ppa:nginx/stablesudo apt-get updatesudo apt-get install nginxabove instructions will install latest stable edition.Nginx installation on Debian and Debian-based distros like UbuntuRun command below to install nginx.sudo apt-get install nginxBy default, Nginx automatically starts when it is installed. You can access the default Nginx landing page to confirm that the software is running properly by visiting your server's domain name or public IP address in your web browser.but if you need latest version, you may need to add official ppa.sudo add-apt-repository ppa:nginx/stablesudo apt-get updatesudo apt-get install nginxRestart NGINXAs a root user:nginx -s restartUbuntu examplesudo service nginx restartReload NGINX configuration fileAs a root user:sudo nginx -s reloadUbuntu 14.04 examplesudo service nginx reloadUbuntu 16.04 examplesudo systemctl reload nginxBefore reloading, it is a good idea to check config for syntax errors:sudo nginx -tOrsudo service nginx configtestShutdown NGINXRun as a root user.Fast shutdown:nginx -s stopGraceful shutdown:nginx -s quitNginx insideOne of the biggest appeals of Nginx is the difference in how it works internally as compared to the other popular servers, specially Apache.Servers are busy programs as they have to serve requests from multiple clients. The more requests a server can successfully serve per second, the better.Nginx works on a concurrency paradigm known as Asynchronous IO.In a conventional server, one thread is dedicated to one request. This means, once a thread takes up a request, it is effectively unavailable for other requests. But in reality, a thread could do a lot better by accepting a bunch of requests and serving them simultaneously. Asynchronous IO is what enables this.Nginx, therefore with its Asynchronous IO architecture, can serve many requests within one thread.Another good thing about Nginx is its relatively leaner resource footprint. Compared to Apache, Nginx is less resource heavy, and this makes it suitable to cloud servers what tend not to be very powerful.There are certainly other Async IO server out there, but Nginx is the most well supported among all in terms of pluginx (aka Nginx Modules).Test if your changes in nginx.config are validUbuntu 14.04 examplesudo nginx -tRead Getting started with nginx online: https:///nginx/topic/1121/getting-started-with-nginxChapter 2: LoggingExamplesBasic exampleSyntaxSyntax: log_format name string ...;Syntax: access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]]; access_log off;Using them togetherlog_format compression '$remote_addr - $remote_user [$time_local] ''"$request" $status $bytes_sent ''"$http_referer" "$http_user_agent" "$gzip_ratio"';access_log /spool/logs/nginx-access.log compression buffer=32k;error_log /spool/logs/nginx-error.log;Reopen log filesAs a root user run:nginx -s reopenAvoid logging for favicon.ico and robots.txtlocation = /favicon.ico {log_not_found off;access_log off;}location = /robots.txt {allow all;log_not_found off;access_log off;}Read Logging online: https:///nginx/topic/2551/loggingChapter 3: Nginx ConfigurationsExamplesConfiguration File’s Structurenginx consists of modules which are controlled by directives specified in the configuration file.Simple DirectivesA simple directive consists of the name and parameters separated by spaces and ends with a semicolon (;).Block DirectiveA block directive has the same structure as a simple directive, but instead of the semicolon it ends with a set of additional instructions surrounded by braces ({ and }).ContextIf a block directive can have other directives inside braces, it is called a context (examples: events, http, server, and location).Directives placed in the configuration file outside of any contexts are considered to be in the main context. The events and http directives reside in the main context, server in http, and location in server.CommentThe rest of a line after the # sign is considered a comment.Test NGINX configuration fileYou can check for syntax errors and referenced files in an NGINX configuration file before running it with:nginx -tAlternatively you can run service scriptservice nginx configtestWhile both of these commands will tell you if your new nginx configuration is ok [without killing your current instance]. Configtest uses the running service and tells you if it passes or fails the check whereas nginx -t will not only check the config but print any info, warning as well as error messages.Source: /nginxapache/nginx-configtest-vs-nginx-t/Specify configuration file to loadnginx -c <file name>Start NGINX with an explicit configuration file.config changes without restartnginx -s reloadLogging to Syslog, incl. mapping of HTTP-Codes to Syslog severities.Paste this snippet somewhere in the http {} Block; or place it in it's own file in the/etc/nginx/conf.d/ folder. Also see the official docs for logging to syslog.## Access Log#log_format fmt_syslog '[$time_local] $status $remote_addr $http_host "$request"$body_bytes_sent $request_time "$http_user_agent" $remote_user';map $status $log_is_error { "~^5\d\d" 1; default 0; }map $status $log_is_warn { "~^4[0-8]{2}" 1; default 0; }map $status $log_is_info { "~^[1-3]\d\d" 1; default 0; }access_logsyslog:server=unix:/run/systemd/journal/syslog,nohostname,facility=local2,severity=errorfmt_syslog if=$log_is_error;access_logsyslog:server=unix:/run/systemd/journal/syslog,nohostname,facility=local2,severity=warnfmt_syslog if=$log_is_warn;access_logsyslog:server=unix:/run/systemd/journal/syslog,nohostname,facility=local2,severity=infofmt_syslog if=$log_is_info;## Error Log#error_log syslog:server=unix:/run/systemd/journal/syslog,nohostname,facility=local2 error;This example assumes rsyslog (or similar) is listening on Socket /run/systemd/journal/syslog - as it's default on Debian 8 when journald has activated ForwardToSyslog. Using this socket, you bypass journald. If that socket is not available try /dev/log instead.Feel free to use another facility instead of local2. You may also change the log_format to suit your needs.Limit request methodsA usual Website just needs 3 HTTP Methods: GET, HEAD and POST. Block all other Methods by using limit_except:location / {[...]# Note: GET includes HEADlimit_except GET POST {deny all;}[...]}Read Nginx Configurations online: https:///nginx/topic/2550/nginx-configurationsChapter 4: nginx reverse proxyExamplessimple reverse proxy# Define which servers to include in the load balancing scheme.# It's best to use the servers' private IPs for better performance and security.upstream backend {ip_hash;server 10.10.10.10 slow_start=30s max_fails=3 fail_timeout=15s;server 10.10.10.12 slow_start=30s max_fails=3 fail_timeout=15s;# Activates the cache for connections to upstream servers.keepalive 20;}# This server accepts all traffic to port 80 and passes it to the upstream.# Notice that the upstream name and the proxy_pass need to match.server {listen 80;server_name ;location / {proxy_pass http://backend/;}}Read nginx reverse proxy online: https:///nginx/topic/7431/nginx-reverse-proxyChapter 5: Useful RedirectsExamplesHTTPS Redirectserver {listen 80 default_server;listen [::]:80 default_server;server_name ;return 307 https://$host$request_uri;}A 301 redirect is also an alternative but if a POST is made to a 301, then many clients willresubmit the request as a GET - which almost always will fail serverside. A 307 mandates thesame request type.Redirect requests to another serverserver {server_name ;return 301 $scheme://$request_uri;}Mobile Site RedirectionNginx configuration to detect request from mobile user-agent and redirect them to mobile site.location / {#mobile site handling as per user agentset $mobile_rewrite do_not_perform; // variable to store action. default set to notperform redirection to mobile site.if ($http_user_agent ~*"(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm(os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|win ce|xda|xiino") {set $mobile_rewrite perform;}if ($http_user_agent ~* "^(1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|awa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s)|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-||_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt(|\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v)|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g|nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-)") {set $mobile_rewrite perform;}#google bot mobile handlingif ($http_user_agent ~* "(googlebot-mobile)") {set $mobile_rewrite perform;}if ($mobile_rewrite = perform) {proxy_pass :$port;}}HTTP location on HTTPS serverHTTPS server with http location:server {listen 443;root /var/www/location / {...}location /http {rewrite ^ http://$host$request_uri? permanent;}}HTTP server redirects to HTTPS except one location:server {root /var/www/location / {rewrite ^ https://$host$request_uri? permanent;}location /http {...}}Disallow Requests Based on Host or Country CodeUse Nginx map to parse fields and reject requests.# Allowed hostsmap $http_host $name {hostnames;default no; yes;* yes; yes;* yes; yes;wap.* yes;}# Allowed countriesmap $geoip_country_code $allowed_country {default no;country_code_1 yes;country_code_2 yes;}server {listen 80 default_server;listen [::]:80 default_server;# Disallow access based on hostnameif ($name = no) {return 444;}# Disallow access based on GeoIPif ($allowed_country = no) {return 444;}...Read Useful Redirects online: https:///nginx/topic/3631/useful-redirectsChapter 6: Using nginx to provide clean browser URLsExamplesRedirect vs reverse proxyProfessionally made web applications don't expose the internal details of the server environment to the user. When you place an order at your retailer, you don't see (or have to type)https://:8443/Dealerapp/entryPage.html, but just , although the app server needs all the details given in the longer URL. This can be achieved via:if ($scheme = http) {return 301 https://$server_name$request_uri;}This does a redirect. Even if the client didn't request a secure connection, the browser is at once redirected to it. In countries having strict data privacy laws, you might even be obliged to do this for any commercial site. The redirect way is taken because here the browser needs to know about the secure connection, otherwise it wouldn't negotiate with the server to make it secure.location /app/ {proxy_pass https://:8443/Dealerapp/entryPage.html;}This is a reverse proxy. It is transparent to the browser. So you can completely hide from the end user whether you have one or more app servers, on which ports they listen, or how their applications are named. Otherwise, if your datacenter needs to move the app to another server that listens on 8543, all bookmarks of your clients would become invalid. This example also directs the user to your entry page. This could be omitted if you name the entry page index.html. But maybe you have several entry pages within an app that the user might want to bookmark, so you are more flexible if you're not bound to index.html.I postfixed the company URL with /app. This could be omitted if your domain only serves this app. In case that in addition to the app, there also is some static content, like your company description, you may want to have the simple URL for that.This proxy only works for the entry page. I usually need two more URL schemes, one for static content of the web app, like JavaScript, CSS, and images. I put all those in a folder structure below a folder called serverapp, and write the following proxy:location /app/serverapp/ {proxy_pass https://:8443/Dealerapp/serverapp/;}And another path for REST services; here the rest URL path doesn't match a folder, but a path of a jax-rs REST service:location /rest/ {proxy_pass https://:8443/Dealerapp/rest/;}One more step, rarely mentioned anywhere, needs to be taken. The app server runs under the URL path /Dealerapp, so it will issue a session cookie having property path=Dealerapp. The browser doesn't know this path, and due to its Same Origin Policy will ignore the cookie. We could convince it via Cross-Origin Resource Sharing to allow this, but it's probably easier to modify the cookie path by setting the path to /, writing something like<session-config><session-timeout>720</session-timeout><cookie-config><name>SZSESSION</name><path>/</path><http-only>true</http-only><secure>true</secure></cookie-config></session-config>to our web.xml.Read Using nginx to provide clean browser URLs online:https:///nginx/topic/6270/using-nginx-to-provide-clean-browser-urlsChapter 7: Wordpress blog integration with rails application using nginxExamplesnginx server blockOnce you have setup and configured the php5-fpm and wordpress settings you can configure the /etc/nginx/conf/nginx.conf file as below.You need to define the location blocks inside the server block and rewrite the url there as defined.server {listen 443 ssl;server_name ;root /home/ubuntu/www/abc/current/public;try_files $uri/index.html $uri @unicorn;ssl on;ssl_certificate /etc/nginx/ssl/abc.crt;ssl_certificate_key /etc/nginx/ssl/abc.key;location /blog/wp-admin/ {root /var/www/html/;index index.php;try_files $uri $uri/ /index.php?$args;location ~* \.(js|css|xml|txt|jpg)$ {expires 14d;root /var/www/html/;access_log off;}location ~ \.php$ {try_files $uri $uri/ /index.php;fastcgi_pass unix:/var/run/php5-fpm.sock;fastcgi_param SCRIPT_FILENAME $request_filename;fastcgi_index index.php;include /etc/nginx/conf/fastcgi_params;}}location ^~ /blog {root /var/www/html/;index index.php;try_files $uri $uri/ /index.php?$args;rewrite ^/blog/(.*)+$ /blog/index.php?$1;location ~* \.(js|css|xml|txt|jpg)$ {expires 14d;root /var/www/html/;access_log off;}location ~ \.php$ {try_files $uri $uri/ /index.php;fastcgi_pass unix:/var/run/php5-fpm.sock;fastcgi_param SCRIPT_FILENAME $request_filename;fastcgi_index index.php;include /etc/nginx/conf/fastcgi_params;}}}Read Wordpress blog integration with rails application using nginx online:https:///nginx/topic/3891/wordpress-blog-integration-with-rails-application-using-nginxCreditshttps:///18。
Nginx搭建(完整版)
目录1搭建nginx需要的安装包-----------------------------------------------------------------------2 2前期准备--------------------------------------------------------------------------------------------22.1 检测-----------------------------------------------------------------------------------------22.2安装libiconv-1.13--------------------------------------------------------------------------22.3安装libmcrypt-2.5.8.----------------------------------------------------------------------22.4安装mhash-0.9.9.9-------------------------------------------------------------------------22.5安装mcrypt-2.6.8--------------------------------------------------------------------------33安装mysql------------------------------------------------------------------------------------------3 3.1创建用户和组--------------------------------------------------------------------------------3 3.2安装编译--------------------------------------------------------------------------------------3 3.3创建MySQL数据库存放目录------------------------------------------------------------3 3.4创建f配置文件-----------------------------------------------------------------------3 3.5创建管理MySQL数据库的shell脚本---------------------------------------------------5 3.6创建账户,赋予关闭的权限----------------------------------------------------------------6 4安装编译php----------------------------------------------------------------------------------------6 4.1 编译php---------------------------------------------------------------------------------------6 4.2编译安装PHP扩展模块--------------------------------------------------------------------74.2.1编译memcache--------------------------------------------------------------------------74.2.2编译eaccelerator-0.9.5.3--------------------------------------------------------------74.2.3编译PDO_MYSQL-1.0.2-------------------------------------------------------------74.2.4编译ImageMagick----------------------------------------------------------------------74.2.5编译imagick-2.2.2-----------------------------------------------------------------------74.3 修改php配置文件------------------------------------------------------------------------74.4配置eAccelerator加速PHP--------------------------------------------------------------84.5创建www用户和组------------------------------------------------------------------------84.6创建虚拟机目录-----------------------------------------------------------------------------84.7创建php-fpm配置文件--------------------------------------------------------------------84.8启动php-cgi进程---------------------------------------------------------------------------12 5安装编译nginx-----------------------------------------------------------------------------------125.1安装Nginx所需的pcre库---------------------------------------------------------------125.2安装Nginx----------------------------------------------------------------------------------125.3建Nginx配置文件-------------------------------------------------------------------------125.4启动Nginx-----------------------------------------------------------------------------------125.5配置开机自动启动Nginx + PHP--------------------------------------------------------135.6优化Linux内核参数-----------------------------------------------------------------------135.7在不停止Nginx服务的情况下平滑变更Nginx配置--------------------------------135.7.1检查配置文件---------------------------------------------------------------------------135.7.2 nginx进程--------------------------------------------------------------------------------145.8编写每天定时切割Nginx日志的脚本---------------------------------------------------145.8.1创建脚本---------------------------------------------------------------------------------145.8.2添加自动任务----------------------------------------------------------------------------146 安装编译memcached-------------------------------------------------------------------------------156.1 安装编译libevent-----------------------------------------------------------------------------156.2 安装编译memcached------------------------------------------------------------------------156.3 启动memcached守护进程-----------------------------------------------------------------156.4 php使用测试--------------------------------------------------------------------------------156.5 停止memcached服务-----------------------------------------------------------------------151、搭建nginx需要的安装包放在219.234.83.29服务器上cd /home/chenjl/software/nginx0.8_basepacage2、前期准备2.1需要安装一些常用的包,在安装服务器时选择安装开发工具,会安装一些常用的包,如果安装了yum,可以用检测一下(【适用CentOS操作系统】)yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers2.2安装libiconv-1.13.tar.gztar zxvf libiconv-1.13.tar.gzcd libiconv-1.13/./configure --prefix=/usr/localmakemake install2.3安装libmcrypt-2.5.8.tar.gztar zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8/./configuremakemake install/sbin/ldconfigcd libltdl/./configure --enable-ltdl-installmakemake install2.4安装mhash-0.9.9.9.tar.gztar zxvf mhash-0.9.9.9.tar.gzcd mhash-0.9.9.9/./configuremakemake installln -s /usr/local/lib/ /usr/lib/ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.soln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.aln -s /usr/local/lib/ /usr/lib/ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.soln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.12.5安装mcrypt-2.6.8.tar.gztar zxvf mcrypt-2.6.8.tar.gzcd mcrypt-2.6.8//sbin/ldconfig./configuremakemake install3、安装mysql3.1 创建用户和组/usr/sbin/groupadd mysql/usr/sbin/useradd -g mysql mysql3.2 安装编译tar zxvf mysql-5.1.38.tar.gzcd mysql-5.1.38/./configure --prefix=/usr/local/mysql/ --enable-assembler --with-extra-charsets=complex --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobasemake && make installchmod +w /usr/local/mysqlchown -R mysql:mysql /usr/local/mysqlmkdir -p /usr/local/mysqldata/3.3创建MySQL数据库存放目录chown -R mysql:mysql /usr/local/mysql/data//usr/local/mysql/bin/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql /data --user=mysql3.4创建f配置文件输入以下内容:###############################[client]default-character-set = utf8port = 3306socket = /tmp/mysql.sock[mysql]prompt="(\u::)[\d]> "no-auto-rehash[mysqld]#default-character-set = utf8user = mysqlport = 3306socket = /tmp/mysql.sockbasedir = /usr/local/mysqldatadir = /usr/local/mysql/dataopen_files_limit = 10240back_log = 600max_connections = 3000max_connect_errors = 6000table_cache = 614external-locking = FALSEmax_allowed_packet = 32Msort_buffer_size = 2Mjoin_buffer_size = 2Mthread_cache_size = 300thread_concurrency = 8query_cache_size = 32Mquery_cache_limit = 2Mquery_cache_min_res_unit = 2kdefault-storage-engine = MyISAMdefault_table_type = MyISAMthread_stack = 192Ktransaction_isolation = READ-COMMITTED tmp_table_size = 246Mmax_heap_table_size = 246Mlong_query_time = 1log_long_formatlog-bin = /data0/mysql/3306/binlogbinlog_cache_size = 4Mbinlog_format = MIXEDmax_binlog_cache_size = 8Mmax_binlog_size = 512Mexpire_logs_days = 7key_buffer_size = 256Mread_buffer_size = 1Mread_rnd_buffer_size = 16Mbulk_insert_buffer_size = 64Mmyisam_sort_buffer_size = 128Mmyisam_max_sort_file_size = 10Gmyisam_max_extra_sort_file_size = 10G myisam_repair_threads = 1myisam_recoverskip-name-resolvemaster-connect-retry = 10slave-skip-errors = 1032,1062,126,1114,1146,1048,1396server-id = 1innodb_additional_mem_pool_size = 16Minnodb_buffer_pool_size = 2048Minnodb_data_file_path = ibdata1:1024M:autoextendinnodb_file_io_threads = 4innodb_thread_concurrency = 8innodb_flush_log_at_trx_commit = 2innodb_log_buffer_size = 16Minnodb_log_file_size = 128Minnodb_log_files_in_group = 3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table = 0[mysqldump]quickmax_allowed_packet = 32M以上数据,根据需要做修改;3.5创建管理MySQL数据库的shell脚本#!/bin/shmysql_port=3306mysql_username="chenjl"mysql_password="cjl1981"function_start_mysql(){printf "Starting MySQL...\n"/bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/usr/local/mysql/f 2>&1 > /dev/null &}function_stop_mysql(){printf "Stoping MySQL...\n"/usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /tmp/mysql.sock shutdown}function_restart_mysql(){printf "Restarting MySQL...\n"function_stop_mysqlsleep 5function_start_mysql}function_kill_mysql(){kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')}if [ "$1" = "start" ]; thenfunction_start_mysqlelif [ "$1" = "stop" ]; thenfunction_stop_mysqlelif [ "$1" = "restart" ]; thenfunction_restart_mysqlelif [ "$1" = "kill" ]; thenfunction_kill_mysqlelseprintf "Usage: /data0/mysql/${mysql_port}/mysql {start|stop|restart|kill}\n"fichmod 755 /usr/local/mysql/bin/mysql.sh3.6 创建账户,赋予关闭的权限/usr/local/mysql/bin/mysql -u root -p -S /tmp/mysql.sockGRANT ALL PRIVILEGES ON *.* TO 'chenjl'@'localhost' IDENTIFIED BY 'cjl1981';GRANT ALL PRIVILEGES ON *.* TO 'chenjl'@'127.0.0.1' IDENTIFIED BY 'cjl1981;4、安装编译php4.1 编译phptar zxvf php-5.2.10.tar.gzgzip -cd php-5.2.10-fpm-0.5.11.diff.gz | patch -d php-5.2.10 -p1cd php-5.2.10/./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pearmake ZEND_EXTRA_LIBS='-liconv'make installcp php.ini-dist /usr/local/php/etc/php.inicurl /go-pear | /usr/local/php/bin/php4.2编译安装PHP扩展模块4.2.1 编译memcachetar zxvf memcache-2.2.5.tgzcd memcache-2.2.5//usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake install启动方式:/usr/local/bin/memcached -d -m 64 -u root -l 127.0.0.1 -p 11211 -c 1024 -P /tmp/memcached.pid4.2.2 编译eaccelerator-0.9.5.3tar jxvf eaccelerator-0.9.5.3.tar.bz2cd eaccelerator-0.9.5.3//usr/local/php/bin/phpize./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-configmakemake install4.2.3编译PDO_MYSQL-1.0.2tar zxvf PDO_MYSQL-1.0.2.tgzcd PDO_MYSQL-1.0.2//usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysqlmakemake install4.2.4编译ImageMagicktar zxvf ImageMagick.tar.gzcd ImageMagick-6.5.1-2/./configure tar zxvf imagick-2.2.2.tgzmakemake instal4.2.5 编译imagick-2.2.2tar zxvf imagick-2.2.2.tgzcd imagick-2.2.2//usr/local/php/bin/phpize./configure --with-php-config=/usr/local/php/bin/php-configmakemake install4.3 修改php配置文件手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = "./"修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"并在此行后增加以下几行,然后保存:extension = "memcache.so"extension = "pdo_mysql.so"extension = "imagick.so"再查找output_buffering = Off修改为output_buffering = On4.4配置eAccelerator加速PHPmkdir -p /usr/local/eaccelerator_cachevi /usr/local/php/etc/php.ini按shift+g键跳到配置文件的最末尾,加上以下配置信息:[eaccelerator]zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eacceler ator.so"eaccelerator.shm_size="64"eaccelerator.cache_dir="/usr/local/eaccelerator_cache"eaccelerator.enable="1"eaccelerator.optimizer="1"eaccelerator.check_mtime="1"eaccelerator.debug="0"eaccelerator.filter=""eaccelerator.shm_max="0"eaccelerator.shm_ttl="3600"eaccelerator.shm_prune_period="3600"eaccelerator.shm_only="0"press="1"press_level="9"4.5创建www用户和组usr/sbin/groupadd www/usr/sbin/useradd -g www www4.6创建虚拟机目录Mkdir /usr/local/wwwChown –R www:www /usr/local/www4.7创建php-fpm配置文件<?xml version="1.0" ?><configuration>All relative paths in this config are relative to php's install prefix<section name="global_options">Pid file<value name="pid_file">/usr/local/php/logs/php-fpm.pid</value>Error log file<value name="error_log">/usr/local/php/logs/php-fpm.log</value>Log level<value name="log_level">notice</value>When this amount of php processes exited with SIGSEGV or SIGBUS ...<value name="emergency_restart_threshold">10</value>... in a less than this interval of time, a graceful restart will be initiated.Useful to work around accidental curruptions in accelerator's shared memory. <value name="emergency_restart_interval">1m</value>Time limit on waiting child's reaction on signals from master<value name="process_control_timeout">5s</value>Set to 'no' to debug fpm<value name="daemonize">yes</value></section><workers><section name="pool">Name of pool. Used in logs and stats.<value name="name">default</value>Address to accept fastcgi requests on.Valid syntax is 'ip.ad.re.ss:port' or just 'port' or '/path/to/unix/socket'<value name="listen_address">127.0.0.1:9000</value><value name="listen_options">Set listen(2) backlog<value name="backlog">-1</value>Set permissions for unix socket, if one used.In Linux read/write permissions must be set in order to allow connections from web server.Many BSD-derrived systems allow connections regardless of permissions.<value name="owner"></value><value name="group"></value><value name="mode">0666</value></value>Additional php.ini defines, specific to this pool of workers.<value name="php_defines"><value name="sendmail_path">/usr/sbin/sendmail -t -i</value><value name="display_errors">1</value></value>Unix user of processes<value name="user">www</value>Unix group of processes<value name="group">www</value>Process manager settings<value name="pm">Sets style of controling worker process count.Valid values are 'static' and 'apache-like'<value name="style">static</value>Sets the limit on the number of simultaneous requests that will be served.Equivalent to Apache MaxClients directive.Equivalent to PHP_FCGI_CHILDREN environment in original php.fcgiUsed with any pm_style.<value name="max_children">128</value>Settings group for 'apache-like' pm style<value name="apache_like">Sets the number of server processes created on startup.Used only when 'apache-like' pm_style is selected<value name="StartServers">20</value>Sets the desired minimum number of idle server processes.Used only when 'apache-like' pm_style is selected<value name="MinSpareServers">5</value>Sets the desired maximum number of idle server processes.Used only when 'apache-like' pm_style is selected<value name="MaxSpareServers">35</value></value></value>The timeout (in seconds) for serving a single request after which the worker process will be terminatedShould be used when 'max_execution_time' ini option does not stop script execution for some reason'0s' means 'off'<value name="request_terminate_timeout">0s</value>The timeout (in seconds) for serving of single request after which a php backtrace will be dumped to slow.log file'0s' means 'off'<value name="request_slowlog_timeout">0s</value>The log file for slow requests<value name="slowlog">logs/slow.log</value>Set open file desc rlimit<value name="rlimit_files">65535</value>Set max core size rlimit<value name="rlimit_core">0</value>Chroot to this directory at the start, absolute path<value name="chroot"></value>Chdir to this directory at the start, absolute path<value name="chdir"></value>Redirect workers' stdout and stderr into main error log.If not set, they will be redirected to /dev/null, according to FastCGI specs<value name="catch_workers_output">yes</value>How much requests each process should execute before respawn.Useful to work around memory leaks in 3rd party libraries.For endless request processing please specify 0Equivalent to PHP_FCGI_MAX_REQUESTS<value name="max_requests">102400</value>Comma separated list of ipv4 addresses of FastCGI clients that allowed to connect.Equivalent to FCGI_WEB_SERVER_ADDRS environment in original php.fcgi (5.2.2+) Makes sense only with AF_INET listening socket.<value name="allowed_clients">127.0.0.1</value>Pass environment variables like LD_LIBRARY_PATHAll $V ARIABLEs are taken from current environment<value name="environment"><value name="HOSTNAME">$HOSTNAME</value><value name="PATH">/usr/local/bin:/usr/bin:/bin</value><value name="TMP">/tmp</value><value name="TMPDIR">/tmp</value><value name="TEMP">/tmp</value><value name="OSTYPE">$OSTYPE</value><value name="MACHTYPE">$MACHTYPE</value><value name="MALLOC_CHECK_">2</value></value></section></workers></configuration>注:请将以下的<value name="display_errors">0</value>改为<value name="display_errors">1</value>,以便显示PHP错误信息,否则,Nginx 会报状态为500的空白错误页)4.8启动php-cgi进程,监听127.0.0.1的9000端口,进程数为200(如果服务器内存小于3GB,可以只开启64个进程),用户为www:ulimit -SHn 65535/usr/local/php/sbin/php-fpm start注:/usr/local/php/sbin/php-fpm还有其他参数,包括:start|stop|quit|restart|reload|logrotate,修改php.ini后不重启php-cgi,重新加载配置文件使用reload。
nginx安装操作说明(正向代理-hls流媒体)
1、安装过程a.# yum install -y pcrepcre-devel# yum install -y opensslopenssl-develb.# tar xzf nginx-1.7.3.tar.gz# cd nginx-1.7.3c.# ./configure(默认安装路径为/usr/local/nginx)d.# make# make installf.启动:nginx# /usr/local/nginx/sbin/nginxe.添加到系统服务将nginx文件直接复制到以下路径/etc/init.d/nginxh.# chmoda+x /etc/init.d/nginx设置权限设置开机启动配置文件rc.local# vim /etc/rc.local添加一行/etc/init.d/nginx start# /etc/init.d/nginx restart 重启测试g.添加用户# useraddnginxI.新建文件夹(对照nginx.cof文件中相关参数路径)[root@localhost/]# cd /opt/[root@localhost/]#mkdir local[root@localhostopt]# cd local[root@localhostlocal]#mkdirtmp[root@localhostlocal]#mkdir cache[root@localhostlocal]#mkdirvar[root@localhostlocal]# cd var/[root@localhostvar]#mkdir log[root@localhostvar]# cd logs/[root@localhostlogs]#mkdirnginx[root@localhostvar]# cd ..[root@localhostlocal]# cd tmp/[root@localhosttmp]#mkdirnginx[root@localhostnginx]# cd nginx[root@localhostnginx]#mkdirproxy_temp注:路径/opt/local/cache主要用来存放直播缓存,大约需要30-100G的存储大小(实时改变),因此建议把路径设置到/opt下2、配置a、替换正向代理配置文件nginx.conf路径/usr/local/nginx/confb、重启nginx# /usr/local/nginx/sbin/nginx -s reload另外相关命令1、查看状态使用ps -ef|grepnginx查看nginx的进程2、停止nginx所有进程[root@linuxidcsbin]#pkill -9 nginx。
nginx安装说明
(1)安装gccrpm -Uvh *.rpm --nodeps –force(2)安装g++rpm -Uvh *.rpm --nodeps –force(3)验证gcc、g++是否安装成功,执行命令:gcc –vg++ -v(4)安装PCRE,先把pcre解压出来,tar -zxvf pcre-8.35.tar.gz,解压出来之后就要开始安装了cd pcre-8.35./configuremakemake install(5)安装libtool,先解压libtool:tar -zxvf libtool-2.4.2.tar.gz,解压出来之后就要开始安装了cd libtool-2.4.2./configuremakemake install(6)安装nginx,先把nginx解压出来tar -zxvf nginx-1.20.1.tar.gz,解压出来之后就要开始安装了cd nginx-1.20.1./configuremakemake install(7)启动nginx: nginx安装目录地址-c nginx配置文件地址,安装后的路径好像会被变到/usr/local里面启动:/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf 停止:/usr/local/nginx/sbin/nginx -s stop重启:/usr/local/nginx/sbin/nginx -s reload查看端口占用:netstat -tunlpgrep(8)nginx的配置文件为安装目录下的nginx目录中的nginx.conf,默认端口为80,启动后出现如下页面即为启动成功访问地址是:服务器地址:80(如:192.168.43.6:80)需要注意80端口有没有被占用。
Nginx安装文档
Nginx安装⽂档前⾔:最近,系统部署⼈员那边,让我们给写⼀个傻⽠式的Nginx安装过程。
所以就有了这个⽂档,本着独乐乐不如众乐乐,就分享⼀下。
我觉得对⼊门⼩⽩来说,有图,乃⾄运⾏过程图,是很重要的(避免运⾏出问题了⽽不⾃知)。
当然,这只是部署⼈员的V1⼿册,后来他们觉得太⿇烦了,就有了yum安装,再就是容器部署等。
后⾯有机会,会写出来的。
同样的话再次提⽰,如果觉得图⽚太⼩,不够清晰,请把图⽚单独打开(简单的,就是拖⼀下图⽚,浏览器会⾃动打开⼀个新的标签页,放置图⽚)。
原图⽚是很清晰的。
⼀,流程概览:这应该是我第⼀次把⾃⼰的笔记暴露出来,字不好看,多多担待哈。
毕竟重点不是字,是知识。
嘻嘻)1. 安装相关依赖。
2. 下载,并解压Nginx压缩包。
3. 配置,编译,及安装Nginx。
4. 启动并验证Nginx。
⼆,安装相关依赖:1. 安装gcc-c++: 安装pcre:安装zlib:安装openssl:PS:依赖的顺序没有要求,并且由于部分系统预先安装了部分依赖的缘故,会安装⽆效,提⽰“aready install“等。
故,可以先安装nginx,根据nginx安装时的错误信息来安装缺乏的软件依赖。
如:(缺乏pcre软件依赖三,下载并解压Nginx压缩包:1. 达到指定⽬录下载压缩包:PS:下载地址不必⼀致,可直接通过阿⾥镜像地址下载,或直接复制⽂件解压压缩包:四,配置,编译,安装Nginx:1. 进⼊Nginx⽬录:配置Nginx:编译Nginx:安装Nginx:五,启动与验证:1. Nginx启动:在nginx程序⽬录下执⾏./nginx1. 验证:执⾏ps aux | grep nginx或登录localhost,查看是否存在以下页⾯:六,⼩结:⾄此Nginx安装完成,出现问题的缘故多是依赖不匹配,系统配置冲突造成。
七,附录:Nginx安装⽬录:/usr/local/nginxNginx配置⽬录:/usr/local/nginx/confNginx程序⽬录:/usr/local/nginx/sbin。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Nginx安装手册
1nginx安装环境
nginx是C语言开发,建议在linux上运行,本教程使用作为安装环境。
⏹gcc
安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:yum install gcc-c++
⏹PCRE
PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括perl 兼容的正则表达式库。
nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yum install -y pcre pcre-devel
注:pcre-devel是使用pcre开发的一个二次开发库。
nginx也需要此库。
⏹zlib
zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。
yum install -y zlib zlib-devel
⏹openssl
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。
nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux 安装openssl库。
yum install -y openssl openssl-devel
2编译安装
将拷贝至linux服务器。
解压:
tar -zxvf --help查询详细参数(参考本教程附录部分:nginx编译参数)
参数设置如下:
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/ \
--lock-path=/var/lock/ \
--error-log-path=/var/log/nginx/ \
--http-log-path=/var/log/nginx/ \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
注意:上边将临时文件目录指定为/var/temp/nginx,需要在/var下创建temp及nginx目录[root@bogon mkdir /var/temp/nginx -p
1、编译安装
make
make install
安装成功查看安装目录:
3启动nginx
cd /usr/local/nginx/sbin/
./nginx
查询nginx进程:
15098是nginx主进程的进程id,15099是nginx工作进程的进程id
注意:执行./nginx启动nginx,这里可以-c指定加载的nginx配置文件,如下:
./nginx -c /usr/local/nginx/conf/
如果不指定-c,nginx在启动时默认加载conf/文件,此文件的地址也可以在编译安装nginx 时指定./configure的参数(--conf-path= 指向配置文件())
4停止nginx
方式1,快速停止:
cd /usr/local/nginx/sbin
./nginx -s stop
此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。
方式2,完整停止(建议使用):
cd /usr/local/nginx/sbin
./nginx -s quit
此方式停止步骤是待nginx进程处理任务完毕进行停止。
5重启nginx
方式1,先停止再启动(建议使用):
对nginx进行重启相当于先停止nginx再启动nginx,即先执行停止命令再执行启动命令。
如下:
./nginx -s quit
./nginx
方式2,重新加载配置文件:
当nginx的配置文件修改后,要想让配置生效需要重启nginx,使用-s reload不用先停止nginx 再启动nginx即可将配置信息在nginx中生效,如下:
./nginx -s reload
6测试
nginx安装成功,启动nginx,即可访问虚拟机上的nginx:
到这说明nginx上安装成功。
若无法访问,
可能是Linux的防火墙的问题:
1.修改文件
vim /etc/sysconfig/iptables
2.关闭防火墙
sevice iptables stop
3.或CentOS7默认使用的是firewall作为防火墙,这里改为iptables防火墙1、关闭firewall:
systemctl stop #停止firewall
systemctl disable #禁止firewall开机启动
2、安装iptables防火墙
yum install iptables-services #安装
3、修改文件配置允许80端口
vi /etc/sysconfig/iptables #编辑防火墙配置文件
按i进入文本编辑在原文档中找到
-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
在该行下面添加
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
:wq! #保存退出
systemctl restart #最后重启防火墙使配置生效systemctl enable #设置防火墙开机启动
7开机自启动nginx
7.1编写shell脚本
这里使用的是编写shell脚本的方式来处理
vi /etc/nginx (输入下面的代码)
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
:wq 保存并退出
7.2设置文件的访问权限
chmod a+x /etc/nginx (a+x ==> all user can execute 所有用户可执行)
这样在控制台就很容易的操作nginx了:查看Nginx当前状态、启动Nginx、停止Nginx、重启Nginx…
如果修改了nginx的配置文件,也可以使用上面的命令重新加载新的配置文件并运行,可以将此命令加入到文件中,这样开机的时候nginx就默认启动了
7.3加入到文件中
vi /etc/
加入一行/etc/nginx start 保存并退出,下次重启会生效。