linux上安装nginx详细步骤

Posted 天枢

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux上安装nginx详细步骤相关的知识,希望对你有一定的参考价值。

一、安装依赖包

yum install gcc gcc-c++ pcre-devel patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel openssl-devel –y

 

二、下载安装nginx

1、下载nginx源码包

wget -c https://nginx.org/download/nginx-1.10.3.tar.gz

2、创建nginx用户

useradd nginx -s /sbin/nologin -M

3、解压

tar -zxvf nginx-1.10.3.tar.gz

4、进入目录

cd nginx-1.10.3

5、生成编译文件

./configure --user=nginx --group=nginx --prefix=/usr/local/nginx-1.10.3/ --with-http_stub_status_module --with-http_ssl_module --with-stream

6、编译

make

7、安装

make install

执行成功后我们可以看一下/usr/local目录下是否有nginx

ll /usr/local/

 

8、做软链接

ln -s /usr/local/nginx-1.10.3 /usr/local/nginx

9、进入nginx程序目录

cd /usr/local/nginx-1.10.3

查看目录结构:ll

 

10、简化nginx配置文件

cd /usr/local/nginx/conf

grep -Ev "#|^$" /usr/local/nginx/conf/nginx.conf.default > /usr/local/nginx/conf/nginx.conf

监测语法

/usr/local/nginx/sbin/nginx -t

 

11、修改nginx配置(删除原有的)

worker_processes  1;
        events {
            worker_connections  1024;
        }
        http {
            include       mime.types;
            default_type  application/octet-stream;
            sendfile        on;
            server {
                listen       80;
                server_name  localhost;
                charset utf-8;
                location / {
                    include uwsgi_params;
                    uwsgi_pass 0.0.0.0:8007;
                    uwsgi_param UWSGI_SCRIPT TSDRM.wsgi;
                    uwsgi_param UWSGI_CHDIR /var/www/html/TSDRM;
                }
                location /static/ {
                    alias /var/www/html/TSDRM/static/;
                }
            }
        }

 

11、启动nginx

cd /usr/local/nginx/sbin

./nginx

 

监测端口

netstat -lntup|grep 80

 

监测进程

ps -ef | grep nginx

 

12、访问nginx

 

注:若想使用外部主机连接上虚拟机访问10.0.0.200,需要关闭虚拟机的防火墙:

systemctl stop firewalld.service

13、nginx关闭与重启

cd /usr/local/nginx/sbin

./nginx -s stop 关闭

./nginx -s reload 重启

 

以上是关于linux上安装nginx详细步骤的主要内容,如果未能解决你的问题,请参考以下文章

Linux 安装Nginx详细步骤

LINUX安装nginx详细步骤

Linux安装Nginx详细步骤

suse 11 怎么安装nginx 求详细步骤

怎么装linux 请详细说明安装步骤和方法!!!!谢谢

Centos7安装Nginx详细安装步骤