1.安装依赖包
//一键安装上面四个依赖
sudo apt-get install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2.下载并解压安装包
//创建一个文件夹
cd /usr/local
mkdir nginx
cd nginx
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -xvf nginx-1.13.7.tar.gz
3.安装nginx
//进入nginx目录
cd /usr/local/nginx
//进入目录
cd nginx-1.13.7
//执行带参数命令
./configure --prefix=/usr/local/soft/nginx --with-http_stub_status_module --with-http_ssl_module
//执行make命令
sudo make
报错
linux@linux:/usr/local/nginx/nginx-1.13.7$ sudo make
make -f objs/Makefile
make[1]: 进入目录“/usr/local/nginx/nginx-1.13.7”
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
-o objs/src/os/unix/ngx_user.o \
src/os/unix/ngx_user.c
src/os/unix/ngx_user.c: In function ‘ngx_libc_crypt’:
src/os/unix/ngx_user.c:26:7: error: ‘struct crypt_data’ has no member named ‘current_salt’
26 | cd.current_salt[0] = ~salt[0];
| ^
make[1]: *** [objs/Makefile:781:objs/src/os/unix/ngx_user.o] 错误 1
make[1]: 离开目录“/usr/local/nginx/nginx-1.13.7”
make: *** [Makefile:8:build] 错误 2
//找到对应文件
sudo vim objs/src/os/unix/ngx_user.c
//注释
/* cd.current_salt[0] = ~salt[0]; */
sudo make
报错
src/http/ngx_http_script.c: In function ‘ngx_http_script_add_copy_code’:
src/http/ngx_http_script.c:698:18: error: cast between incompatible function types from ‘size_t (*)(ngx_http_script_engine_t *)’ {aka ‘long unsigned int (*)(struct <anonymous> *)’} to ‘void (*)(ngx_http_script_engine_t *)’ {aka ‘void (*)(struct <anonymous> *)’} [-Werror=cast-function-type]
698 | code->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
| ^
src/http/ngx_http_script.c: In function ‘ngx_http_script_add_var_code’:
src/http/ngx_http_script.c:787:18: error: cast between incompatible function types from ‘size_t (*)(ngx_http_script_engine_t *)’ {aka ‘long unsigned int (*)(struct <anonymous> *)’} to ‘void (*)(ngx_http_script_engine_t *)’ {aka ‘void (*)(struct <anonymous> *)’} [-Werror=cast-function-type]
787 | code->code = (ngx_http_script_code_pt) ngx_http_script_copy_var_len_code;
| ^
src/http/ngx_http_script.c: In function ‘ngx_http_script_add_capture_code’:
src/http/ngx_http_script.c:1181:18: error: cast between incompatible function types from ‘size_t (*)(ngx_http_script_engine_t *)’ {aka ‘long unsigned int (*)(struct <anonymous> *)’} to ‘void (*)(ngx_http_script_engine_t *)’ {aka ‘void (*)(struct <anonymous> *)’} [-Werror=cast-function-type]
1181 | code->code = (ngx_http_script_code_pt)
| ^
src/http/ngx_http_script.c: In function ‘ngx_http_script_add_full_name_code’:
src/http/ngx_http_script.c:1296:18: error: cast between incompatible function types from ‘size_t (*)(ngx_http_script_engine_t *)’ {aka ‘long unsigned int (*)(struct <anonymous> *)’} to ‘void (*)(ngx_http_script_engine_t *)’ {aka ‘void (*)(struct <anonymous> *)’} [-Werror=cast-function-type]
1296 | code->code = (ngx_http_script_code_pt) ngx_http_script_full_name_len_code;
| ^
cc1: all warnings being treated as errors
make[1]: *** [objs/Makefile:886:objs/src/http/ngx_http_script.o] 错误 1
make[1]: 离开目录“/usr/local/nginx/nginx-1.13.7”
make: *** [Makefile:8:build] 错误 2
//将对应文件 /nginx-1.10.3/objs/Makefile 中的 -Werrori 去掉 重新make
sudo vim objs/Makefile
去掉 -Werrori
4.配置nginx.conf
//打开配置文件
vim /usr/local/nginx/conf/nginx.conf
具体位置不同
localhost修改为你服务器ip地址。
5.启动nginx
cd obj
./nginx
//查看nginx进程是否启动:
ps -ef | grep nginx
linux@linux:/usr/local/nginx/nginx-1.13.7/objs$ ps -ef|grep nginx
root 18366 1662 0 16:59 ? 00:00:00 nginx: master process ./nginx
nobody 18367 18366 0 16:59 ? 00:00:00 nginx: worker process
linux 18369 4559 0 16:59 pts/2 00:00:00 grep --color=auto nginx
6.外部主机连接关闭虚拟机的防火墙
centOS6使用命令: systemctl stop iptables.service
centOS7使用命令: systemctl stop firewalld.service
Ubuntu16使用命令: ufw disable
随后同一网络下任意浏览器输入ip即可看到nginx界面
Welcome 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 nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
7.访问服务器ip查看
安装完成一般常用命令
//进入安装目录中
cd /usr/local/nginx/obj
不同版本位置不同但都在安装目录下
//启动,关闭,重启,命令:
./nginx 启动
./nginx -s stop 关闭
./nginx -s reload 重启
————————————————
8.测试
将indelx.html复制到nginx 的html下查看效果