Mac上Nginx服务搭建
2019-08-21 本文已影响0人
MichaelDing
什么是Nginx? 百度百科 官网解释
Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务。Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,第一个公开版本0.1.0发布于2004年10月4日,
在连接高并发的情况下,Nginx是Apache服务不错的替代品:Nginx在美国是做虚拟主机生意的老板们经常选择的软件平台之一。能够支持高达 50,000 个并发连接数的响应,感谢Nginx为我们选择了 epoll and kqueue作为开发模型
Nginx搭建(远程阿里云服务器搭建)
- 使用ssh方式登录云服务器(请自备账号密码)
Last login: Wed Aug 21 09:12:30 on ttys003
CharlesdeMac-mini:~ charles$ ssh root@112.31.3.254
root@112.31.3.254's password:
Last login: Wed Aug 21 09:12:30 on ttys003
CharlesdeMac-mini:~ charles$ ssh root@118.31.3.252
root@112.31.3.254's password:
Connection closed by 12.31.3.254 port 28
CharlesdeMac-mini:~ charles$ ssh root@112.31.3.254
root@112.31.3.254's password:
Last login: Wed Aug 21 09:13:24 2019 from 114.222.210.122
Welcome to Alibaba Cloud Elastic Compute Service !
[root@lha ~]#
- 在服务器的usr/local目录下新建nginx目录和tools目录
cd /usr/local
mkdir nginx
mkdir tools
进入tools目录使用命令下载nginx包,并解压
cd /usr/local/tools
wget http://nginx.org/download/nginx-1.6.2.tar.gz
tar xvzf nginx-1.6.2.tar.gz
解压完毕,应该生成了一个nginx-xxx-xx的目录,进入此目录,然后进行编译,指定nginx的安装目录为我们之前新建的目录,我这里是/usr/local/nginx
cd nginx-xxx-xxx
./configure --prefix=/usr/local/nginx
编译完毕之后安装,注意编译之前准备工作中的依赖包一定要全部ok,不然会报错,如果依赖ok还报错就重启服务器试一试
cd nginx-xxx-xxx
./configure --prefix=/usr/local/nginx
启动nginx
cd /usr/local/nginx
./sbin/nginx
至此Nginx在Mac上安装完成,是不是很简单
Nginx配置虚拟主机步骤
- 进入Nginx nginx.conf配置文件目录,配置虚拟目录,进入编辑模式i,wq:保存
[root@lha local]# cd /usr/local/nginx/conf
[root@lha conf]# ls
fastcgi.conf mime.types uwsgi_params
fastcgi.conf.default mime.types.default uwsgi_params.default
fastcgi_params nginx.conf vim
fastcgi_params.default nginx.conf.default win-utf
koi-utf scgi_params
koi-win scgi_params.default
server {
listen 80;
server_name 118.31.3.252;
location / {
root /usr/local/static;
autoindex on;
charset utf-8,gbk;
autoindex_exact_size on;
autoindex_localtime on;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
- 进入Nginx使配置文件生效
cd /usr/local/nginx
./sbin/nginx
- 进入usr/local目录新建 static目录,再在static目录下新建一个upload子目录
cd /usr/local
mkdir static
cd /usr/local/
mkdir upload
[root@lha local]# ls
aegis etc include lib64 nginx share static webserver
bin games lib libexec sbin src upload
[root@lha local]# cd static
[root@lha static]# ls
upload
[root@lha static]# ls
upload
upload目录存放我们上传的图片或者html
- 上传图片或者html到/usr/local/static/upload
终端情况下按command +n可另开一个终端
使用命令终端上传scp /Users/charles/Desktop/imagePath/C语言.jpg root@118.31.3.252:/usr/local/static/upload
Last login: Wed Aug 21 09:54:56 on ttys003
CharlesdeMac-mini:~ charles$ scp /Users/charles/Desktop/imagePath/C语言.jpg root@118.31.3.252:/usr/local/static/upload
root@112.32.3.252's password:
C语言.jpg 100% 15KB 450.5KB/s 00:00
CharlesdeMac-mini:~ charles$


至此图片上传完毕,html类似操作
- 通过Nginx地址 http://118.31.3.252/upload/C语言.jpg 访问图片
C语言图片
CA3F7EC0-8354-4419-A8CB-98E161209568.png