当前位置:首页 » 操作系统 » nginx安装linux

nginx安装linux

发布时间: 2022-09-04 14:32:11

‘壹’ 如何在linux中安装nginx

第一步:下载相应的版本nginx-1.5.9.tar.gz
第二步:解压 tar -zxvf nginx-1.5.9.tar.gz
第三步:设置一下配置信息 ./configure --prefix=/usr/local/nginx ,或者不执行此步,直接默认配置
第四步:
make 编译 (make的过程是把各种语言写的源码文件,变成可执行文件和各种库文件)
make install 安装 (make install是把这些编译出来的可执行文件和库文件复制到合适的地方)

‘贰’ nginx 安装linux下什么目录

首先,查找nginx的安装信息

rpm-qa|grepnginx

这样就看到了全部的目录地址!

附:

linux 查找安装包路径,查看yum 安装软件包的路径

‘叁’ nginx怎么安装在linux中

一、下载→编译→安装→启动
1.下载nginx最新版
到官方网站上下载最新的tar.gz包
直接下载nginx的url为http://nginx.org/download/nginx-{version}.tar.gz,其中{version}为nginx的版本号
命令:[root@localhost ~]# wget http://nginx.org/download/nginx-1.9.14.tar.gz
2.解压文件
[root@localhost ~]# tar -zvxf nginx-1.9.14.tar.gz
3.进入nginx解压目录
[root@localhost ~]# cd nginx-1.9.14
4.使用参数进行编译,后面会给出编译参数的具体解释
[root@localhost nginx-1.9.14]# ./configure –prefix=/etc/nginx –sbin-path=/usr/sbin/nginx –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_mole –with-http_realip_mole –with-http_addition_mole –with-http_sub_mole –with-http_dav_mole –with-http_flv_mole –with-http_mp4_mole –with-http_gunzip_mole –with-http_gzip_static_mole –with-http_random_index_mole –with-http_secure_link_mole –with-http_stub_status_mole –with-http_auth_request_mole –with-mail –with-mail_ssl_mole –with-file-aio –with-ipv6 –with-http_v2_mole
5.执行编译过程
[root@localhost nginx-1.9.14]# make && make install
6.配置nginx.conf
7.启动nginx
[root@localhost nginx-1.9.14]# nginx
二、编译参数
–prefix=path
定义保存服务器文件的目录。这个目录同时将作用于nginx.conf配置文件中配置的相对路径(但不包括源码库的路径)。默认值为/usr/local/nginx。
–sbin-path=path
设置nginx可执行文件的名称,该名称只在安装期间使用。默认值是prefix/sbin/nginx
–conf-path=path
设置nginx.conf配置文件的名称。如果需要,nginx可以使用不同的配置文件启动,你可以通过命令行参数 -c file启动。默认文件名为prefix/conf/nginx.conf
–pid-path=path
设置nginx.pid文件的名称,nginx.pid用于存储主进程的进程ID。安装后,该文件名称可以在nginx.conf的pid指令中修改。默认为prefix/logs/nginx.pid
–error-log-path=path
设置重要的错误、警告以及诊断文件的名字。安装后,可以通过nginx.conf的error_log指令修改。默认为prefix/logs/error.log
–http-log-path=path
记录主要请求日志的名称,安装后通过access_log指令修改。默认为prefix/logs/access.log
–user=name
设置工作进程的用户名,安装后可以通过user指令修改。默认值为nobody
–group=name
设置工作进程的用户组,安皇后可以通过user指令修改,默认与user相同。
–with-xxx_mole
安装xxx模块,这些模块可以在nginx文档中找到。
–without-xxx_mole
不安装xxx模块(有些模块是默认安装的,如果不想安装,可以通过这个参数屏蔽),这些模块可以在nginx文档中找到。

‘肆’ 如何在远程Linux服务器上搭建Nginx

1.将nginx的压缩包nginx-1.8.0.tar.gz上传到Linux服务器

2.由于nginx是C语言开发的并且我们这里是通过编译nginx的源码来安装nginx,所以Linux上要安装C语言的编译环境gcc,

如果已经安装此步可以省略,否则执行命令:

yum install gcc-c++

3.nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。

yum install -y pcre pcre-devel

4.zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。

yum install -y zlib zlib-devel

5.nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。

yum install -y openssl openssl-devel

6.在Linux上创建nginx的临时目录,注意我这里是在Linux文件系统下的
/var下创建文件夹temp在temp下创建nginx。即:/var/temp/nginx

7.执行命令:

./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_mole --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

8.编译源码,安装nginx:

makemake install

9.启动nginx:

cd /usr/local/nginx/sbin/./nginx -c /usr/local/nginx/conf/nginx.conf

在浏览器中访问: http://localhost 出现下面界面表示安装成功:

我们此时也可以查看到nginx进程的运行情况:

ps aux|grep nginx

10.nginx服务器的停止方式:

方式一:先查出nginx进程id再使用kill命令强制杀掉进程。

cd /usr/local/nginx/sbin./nginx -s stop

方式二(推荐):待nginx进程处理任务完毕进行停止。

cd /usr/local/nginx/sbin./nginx -s quit

以上就是本文的全部内容,希望对大家的学习有所帮助

‘伍’ 如何在linux上安装nginx

#forcentos
yuminstall-yepel-release&&yumcleanall&&yummakecache
yuminstall-ynginx

如果编译安装的话需要很多依赖包。YUM安装是最简单的。

‘陆’ 如何在linux下搭建nginx服务器

1、下载后解压nginx

tar -zxvf nginx-1.4.7.tar.gz
2、安装gcc等依赖包
yum -y install gcc pcre-devel openssl openssl-devel
3、开始安装nginx
cd进入nginx-1.4.7目录内
./configure 编译
make&&make install 这一步需要先cd出来吗?在里面会安装失败吗?我忘了 = =
4、此时就已经安装完成,默认安装在了/usr/local/nginx/sbin/nginx
5、启动
命令行输入/usr/local/nginx/sbin/nginx,没反应
输入ps -ef | grep nginx查看nginx进程
6、测试
命令行输入 curl http://127.0.0.1
会出现welcome to nginx之类的就说明对了!
7、加入到环境变量
vim /etc/profile
尾行添加
PATH=$PATH:/usr/local/nginx/sbin
export PATH
保存关闭后运行 source /etc/profile 即会加入环境变量
8、常用命令
[root@ usr]# nginx -s stop停止nginx
[root@ usr]# nginx 运行nginx
[root@ usr]# nginx -s reload 重启nginx
[root@ usr]# nginx -t 测试nginx
9、防火墙允许外网访问
vim /etc/sysconfig/iptables
添加过滤规则
-A -INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
好像是保存后即时生效把?
service iptables stop
service iptables start
重启服务后还是会生效,亲测
10、修改网站默认根目录路径
网站默认根目录放在/usr/local/nginx/html
命令行输入 vim /usr/local/nginx/conf/nginx.conf
找到改为
server {
listen 80;
server_name localhost;
root /var/www/html/default;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root html;
index index.html index.htm;
}
注释掉下面的,在上面添加自己想要的根目录,重启nginx才能生效。

‘柒’ linux上怎么安装nginx

1.先从nginx官网下载最新的版本

2.解压nginx-1.7.8.tar.gz,然后执行下面操作即可

./configure --prefix=/usr/local/nginx

make

make install

‘捌’ linux 下nginx模块的安装

安装

第一步 下载并解压Nginx压缩包

从Nginx官网下载Nginx,或者在Linux上执行wget http://nginx.org/download/nginx-1.10.1.tar.gz命令直接下载
解压nginx-1.10.1.tar.gz文件:

tar zxvf nginx-1.10.1.tar.gz
1
1
第二步 配置

cd nginx-1.10.1
./configure --prefix=/usr/local/nginx
1
2
1
2
注意:
① 如果之前没有安装C compiler(C 编译器),这一步将报如下错误信息:

xueliang@dev:~/download/nginx-1.10.1$ ./configure –prefix=/usr/local/nginx
checking for OS
+ Linux 4.2.0-27-generic x86_64
checking for C compiler … not found

./configure: error: C compiler cc is not found

xueliang@dev:~/download/nginx-1.10.1$
可以参考这篇文章安装C compiler,然后继续下面的操作

② 如果之前没有安装PCRE,这一步将报如下错误信息:

checking for PCRE library … not found
checking for PCRE library in /usr/local/ … not found
checking for PCRE library in /usr/include/pcre/ … not found
checking for PCRE library in /usr/pkg/ … not found
checking for PCRE library in /opt/local/ … not found

./configure: error: the HTTP rewrite mole requires the PCRE library.
You can either disable the mole by using –without-http_rewrite_mole
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using –with-pcre= option.

xueliang@dev:~/download/nginx-1.10.1$

③ 如果之前没有安装zlib,这一步将报如下错误信息:

checking for md5 in system md library … not found
checking for md5 in system md5 library … not found
checking for md5 in system OpenSSL crypto library … not found
checking for sha1 in system md library … not found
checking for sha1 in system OpenSSL crypto library … not found
checking for zlib library … not found

./configure: error: the HTTP gzip mole requires the zlib library.
You can either disable the mole by using –without-http_gzip_mole
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using –with-zlib= option.

xueliang@dev:~/download/nginx-1.10.1$

也可以跳过此步,执行默认安装,--prefix的默认值为/usr/local/nginx,Nginx官网对此有说明:Building nginx from Sources

‘玖’ linux系统怎么安装nginx

这里以CentOS6.6系统(32位)中安装nginx的源码包,进行讲解。
1. nginx源码包的下载
nginx官方下载地址:http://nginx.org/
选择你要安装的nginx版本,这里,我选择的是 nginx-1.10.2 。
具体的下载链接为:http://nginx.org/download/nginx-1.10.2.tar.gz
可以在其他电脑下载好,通过ftp软件传给要安装的linux电脑。也可以直接在linux电脑上使用wget命令下载。这里我们使用后一种方式。
在linux的根目录,创建一个多级空目录 /my_package/source,用来存放下载的源码包。
mkdir -p /my_package/sourcecd /my_package/source12

执行下载命令:
wget http://nginx.org/download/nginx-1.10.2.tar.gz1

下载完成后,在 /my_package/source 目录中,就有了 nginx-1.10.2.tar.gz 源码包压缩文件。
2. nginx的安装与配置
2.1 准备工作
安装nginx之前,需要先安装pcre库。如果你的linux系统中没有pcre,需要先进行安装。
这里,我们使用yum工具,在线快速安装pcre:
yum -y install pcre
yum -y install pcre-devel12

可以通过下面的命令,找到已安装的pcre和pcre-devel的位置:
rpm -ql pcre
rpm -ql pcre-devel或
find / -name "*pcre*"1234

2.2 nginx的安装
配置nginx安装的参数,比如:安装路径,指定依赖库的具体位置等。
这里我们使用默认安装配置:
tar -zxvf nginx-1.10.2.tar.gzcd nginx-1.10.2./configure123

如果这一步执行正确,在提示信息中会告知nginx将要安装的位置、可执行文件的位置等,如下:
nginx path prefix: "/usr/local/nginx"nginx binary file: "/usr/local/nginx/sbin/nginx"nginx moles path: "/usr/local/nginx/moles"nginx configuration prefix: "/usr/local/nginx/conf"nginx configuration file: "/usr/local/nginx/conf/nginx.conf"nginx pid file: "/usr/local/nginx/logs/nginx.pid"nginx error log file: "/usr/local/nginx/logs/error.log"nginx http access log file: "/usr/local/nginx/logs/access.log"nginx http client request body temporary files: "client_body_temp"nginx http proxy temporary files: "proxy_temp"nginx http fastcgi temporary files: "fastcgi_temp"nginx http uwsgi temporary files: "uwsgi_temp"nginx http scgi temporary files: "scgi_temp"12345678910111213

如果这一步出错了,根据错误提示信息解决问题后,使用 make clean 命令,清除产生的临时文件,再来重新执行 ./configure
如果想查看具体可以配置哪些安装参数,可以使用下面的命令查看:
./configure --help1

编译和安装
makemake install12

到此,nginx的源码包就安装完毕了。
2.3 nginx的配置
如果想修改nginx的配置文件,可使用下面的命令:
vi /usr/local/nginx/conf/nginx.conf1

3. nginx的常用命令
检查测试nginx的配置信息是否正确
/usr/local/nginx/sbin/nginx -t1

启动nginx
/usr/local/nginx/sbin/nginx1

启动nginx服务器后,可以使用下面的命令检测nginx是否启动成功,并查看nginx的端口、主进程号、进程名称等信息。
netstat -tlunp1

也可以使用下面的命令检测nginx是否启动成功,并查看nginx的主进程和子进程的详细信息。
ps aux | grep nginx1

ps aux 命令(a代表前台进程,x代表后台进程,u代表进程的发起者)列出的进程信息中,主要包含以下信息:USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 。这里,简单说明一下:
USER:表示进程的发起者,也就是说,进程是哪个用户产生的。
PID:表示进程的id,也称作,进程号。%CPU:表示进程占用的CPU资源的百分比。%MEM:表示进程占用的物理内存的百分比。
VSZ:表示进程占用的虚拟内存的大小,单位KB。
RSS:表示进程占用的实际物理内存的大小,单位KB。
TTY:表示进程是在哪个终端中运行的。其中tty1到tty7代表本地控制台终端,tty1到tty6是本地的字符界面终端,tty7是图形终端。pts/0-255代表虚拟终端(即远程登录终端)。
STAT:表示进程的状态。常见的状态有:R 运行;S 睡眠;T 停止;s 包含子进程;+ 位于后台。
START:表示进程是在什么时间启动的。
TIME:表示进程占用CPU的运算时间,值越大,越耗费资源。
COMMAND:表示产生该进程的命令(通过它可以识别正在运行的进程名)。1234567891011

成功启动nginx后,就可以在本地电脑或其他电脑中访问你的nginx服务器中的网站了。
本地电脑(即nginx所在的电脑)的访问方式:curl 127.0.0.1
其他电脑(局域网内)的访问方式:打开浏览器,输入nginx服务器的局域网IP即可。12

为了更方便的使用 /usr/local/nginx/sbin 中的命令,
我们将其加入linux系统的环境变量,即修改文件 /etc/profile,在最后加入下面的代码:
export PATH="/usr/local/nginx/sbin:$PATH"1

保存退出后,执行命令:source /etc/profile 可使该配置文件立即生效。
关闭nginx
nginx -s stop 快速关闭nginx
nginx -s quit 平滑关闭nginx
kill -s QUIT 11247 通过linux的kill命令杀死nginx进程,11247为nginx的主进程号123

重新加载nginx的配置文件
nginx -s reload 修改了nginx的配置文件后,可以使用该命令让新的配置立即生效,而不用重启整个nginx服务器

希望我的方法能够帮助到你

热点内容
sqldist 发布:2025-05-14 18:08:18 浏览:161
人行外管局编译 发布:2025-05-14 18:07:33 浏览:648
安卓手机如何使用大流量 发布:2025-05-14 17:47:34 浏览:81
精密模具编程 发布:2025-05-14 17:45:16 浏览:499
存储顺序和逻辑顺序有什么区别 发布:2025-05-14 17:44:30 浏览:275
安卓版设置里的隐身在哪里 发布:2025-05-14 17:35:16 浏览:333
linuxshell密码 发布:2025-05-14 17:21:11 浏览:200
安卓手机听筒在哪里关闭 发布:2025-05-14 17:16:20 浏览:456
我的世界炸毁50万服务器 发布:2025-05-14 17:16:07 浏览:123
存储站源 发布:2025-05-14 17:14:20 浏览:864