主页 M

Ubuntu中nginx源码安装、配置

2020-04-26 网页编程网 网页编程网

1.下载解压源码

Nginx承受3万并发连接数,胜过Apache10倍。在/usr/local/src解压tar xf nginx-1.16.1.tar.gz

2.安装依赖

sudo apt-get update   
sudo apt-get install libpcre3 libpcre3-dev 
sudo apt-get install zlib1g-dev
sudo apt-get install build-essential

3.预编译,编译与安装

切换到root账户。

useradd -s /sbin/nologin www#生成用户,且不能登录
id www#查看用户
[root@node4 nginx-1.16.1]# ./configure --prefix=/usr/local/nginx
[root@node4 nginx-1.16.1]# make && make install

若要安装查看性能模块可用 ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module。查看是否编译成功,以下二选一(if后面的中括号[ $? -eq 0 ],括号的两边需要有一个空格。)。

echo $?
if[ $? -eq 0 ]:then echo success;fi

4.启动

[root@node4 nginx]# /usr/local/nginx/sbin/nginx

5.查看进程、端口

[root@node4 nginx]# ps -ef |grep nginx
[root@node4 nginx]# netstat -ntlp |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN

6.修改配置

vim /usr/local/nginx/conf/nginx.conf
user nginx;
。。。
location / {
	root html/upload;
	index index.php index.html index.htm;
}
+-- 17 行: error_page 404 /404.html;-----------
#
location ~ \.php$ {
	root html/upload;
	fastcgi_pass 127.0.0.1:9000;
	fastcgi_index index.php;
	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	include fastcgi_params;
。。。
# 重启nginx服务:
/usr/local/nginx/sbin/nginx -s reload

7.上传网站源码修改权限

unzip Discuz_X3.1_SC_UTF8.zip -d /usr/local/nginx/html
chown nginx. -R /usr/local/nginx/html/

8.停止等操作

nginx -s quit
nginx -s stop
systemctl stop nginx.service
killall nginx#若以上无效

9.查看安装目录

# ps -ef | grep nginx
root 4593 1  0 Jan23 ?  00:00:00 nginx: master process /usr/sbin/nginx

10.查看nginx.conf配置文件目录

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

11.启动nginx服务

# nginx安装目录 -c nginx.conf配置文件目录

其中:参数 “-c” 指定了配置文件的路径,如果不加 “-c” 参数,Nginx 会默认加载其安装目录的 conf 子目录中的 nginx.conf 文件。

12.查找安装目录、配置文件

查看软件安装路径:whereis nginx

查询运行文件所在路径:which nginx

阅读原文
阅读 2815
123 显示电脑版