当前位置:首页 » 操作系统 » linux下的nginx

linux下的nginx

发布时间: 2022-05-21 13:50:00

1. linux下nginx怎么使用

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

2. 如何在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才能生效。

3. 如何查看linux 下 nginx配置

默认的路径是你安装时候指定的
如果用的lnmp之类的安装包
你可以在shell下
whereisnginx
找到相应的路径之后
在nginx下的conf文件夹里看配置文件,日志文件如果记录了话
在配置文件里有路径的~

4. linux中启动Nginx

nginx的启动命令是:
/usr/local/nginx/sbin/nginx
-c
/usr/local/nginx/conf/nginx.conf
-c制定配置文件的路径,不加-nginx会自动加载默认路径的配置文件。
以上是通用的启动命令

5. 如何在linux下编译nginx

安装nginx
1.下载
2.解压
复制代码代码如下:
tar
-zxvf
nginx-1.7.0.tar.gz
3.编译和安装
执行如下命令:
# cd nginx-1.7.0# ./configure --prefix=/usr/local/nginx-1.7.0 \--with-http_ssl_mole --with-http_spdy_mole \--with-http_stub_status_mole --with-pcre
–with-http_stub_status_mole:支持nginx状态查询–with-http_ssl_mole:支持https–with-http_spdy_mole:支持google的spdy,想了解请网络spdy,这个必须有ssl的支持–with-pcre:为了支持rewrite重写功能,必须制定pcre最后输出如下内容,表示configure
OK了。

6. 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

7. 启动nginx命令linux下

方法1:找到nginx的路径和nginx配置文件的路径,然后运行
/usr/具体路径/nginx -c /usr/具体路径/nginx.conf
方法2:找到nginx路径
工作目录切换到nginx下:cd /usr/具体路径/sbin
然后运行nginx软件: ./nginx

8. linux下nginx一直杀不完是什么原因

nginx的进程分为Master进程和worker进程,worker进程是Master派生出来的子进程,其数量始终维持在一个数量上,当缺少一个worker进程是,Master就会派生一个新的子进程。所以你杀worker进程是杀不完的。
可以这样做:
kill `pgrep -o nginx`
解释一下:
pgrep -o nginx 查看第一个启动的进程号,一般就是主进程号了。
kill `pgrep -o nginx` 等价于 kill 主进程号。

9. linux下如何重启nginx

1、第一种方法:首先在进入nginx可执行目录bin,输入代码:cd /usr/local/nglnx/sbln。

10. 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服务器

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

热点内容
存储过程性能 发布:2024-10-25 23:35:39 浏览:111
同一个ip是不是同一个服务器 发布:2024-10-25 23:33:15 浏览:518
为啥c语言要编译器啊 发布:2024-10-25 23:32:38 浏览:218
快存储 发布:2024-10-25 23:31:05 浏览:286
算法制造 发布:2024-10-25 23:11:27 浏览:886
台式电脑安装哪个安卓系统好 发布:2024-10-25 23:11:25 浏览:114
怎么样学电脑编程 发布:2024-10-25 23:10:13 浏览:524
安卓手机内存占用太多如何清理 发布:2024-10-25 23:03:53 浏览:910
swift项目编译 发布:2024-10-25 22:53:12 浏览:963
迈锐宝买哪个配置合算 发布:2024-10-25 22:28:59 浏览:994