ubuntu安装nginx详细步骤

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下查看效果

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值