学习nginx(一):安装

1.Windows安装:下载+解压,运行nginx.exe就行

2.linux安装:

前置条件:安装了GCC编译器(build-essential)、openSSL

1)安装基本组件

wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
wget http://zlib.net/zlib-1.2.11.tar.gz

然后解压这些软件包

之后请使用root用户操作

先后进入 pcre、zlib,执行:

./configure && make && make install

编译并安装

2)解压并使用上述相同命令编译并安装nginx

执行nginx的configure文件时,可以通过一些参数指定安装位置等信息,详见:Nginx编译选项

例如默认把nginx安装到 /usr/local/nginx,而我们希望安装到 /home/user/nginx,则可以执行如下命令:

./configure --prefix=/home/user/nginx && make && make install

再比如,nginx默认带有很多模块,如果有某个模块我们不想编译到程序中,就可以用 --without--模块名 排除它

如果我们想把自己编写的模块编译进程序里,则可以使用 --add-module=<模块全路径>  添加

3)创建nginx的别名

安装完nginx之后,直接输入"nginx",会提示(ubuntu 16.04,反正意思就是nginx还没安装)

The program 'nginx' can be found in the following packages:
 * nginx-core
 * nginx-extras
 * nginx-full
 * nginx-light
Try: apt install <selected package>

这时先使用 whereis nginx 找到程序安装到哪里(一般是 /usr/local/nginx)

先试试是不是真的安装到这里:

cd /usr/local/nginx && sbin/nginx

然后访问 80 端口,如果看到欢迎页面,说明安装成功

但是如果每次都这样启动太麻烦了,所以给它创建一个别名

编辑/etc/profile,或者~/.bashrc

添加 alias nginx="/usr/local/nginx/sbin/nginx" 

然后使用source命令生效即可

安装之后,目录如下:

ubuntu@VM-0-6-ubuntu:/usr/local/nginx$ sudo ls *
conf:
fastcgi.conf            koi-win             scgi_params
fastcgi.conf.default    mime.types          scgi_params.default
fastcgi_params          mime.types.default  uwsgi_params
fastcgi_params.default  nginx.conf          uwsgi_params.default
koi-utf                 nginx.conf.default  win-utf

html:
50x.html  index.html

logs:
access.log  error.log

sbin:
nginx

各个目录的作用顾名思义:

conf:放置各种配置文件,比较关键的就是 nginx.conf

html:默认的欢迎页面和错误页面

logs:存放日志、pid、lock文件的地方

sbin:存放主程序

猜你喜欢

转载自blog.csdn.net/u010670411/article/details/84667932