linux下安装nginx

Nginx 安装与部署

一 准备

腾讯云服务器/centos7系统

Nginx:nginx-1.13.1

二 安装

Nginx依赖

-gcc、gcc-c++

yum install gcc

yum install gcc-c++

-pcre、zlib

yum -y install pcre*

yum -y install zlib*

-openssl

yum -y install openssl

yum -y install openssl-devel

-Nginx安装

下载Nginx安装包

wget http://nginx.org/download/nginx-1.13.1.tar.gz

解压

tar -z -xv -f nginx-1.13.1.tar.gz

配置

cd nginx-1.13.1

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre //会报错

./configure --prefix=/usr/local/nginx //那就执行这个


–prefix:设置安装路径

–with-http_stub_status_module:支持nginx状态查询

–with-http_ssl_module:支持https

–with-pcre:为了支持rewrite重写功能,必须制定pcre


编译

make

make install

make install 这条指令需要当前文件夹下有Makefile才能成功

启动

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

测试(关闭防火墙)

访问http://ip/

linux下安装nginx

Nginx 多域名绑定

实现最终结果:一个ip绑定多个域名


准备

-安装好Nginx

还未安装好可参考博主的另一文章:Nginx 安装与部署

-域名

申请的域名需要实名验证备案通过才可以使用,详情咨询服务商

实现

找到nginx.conf配置文件

# nginx安装位置查找

[root@VM_0_3_centos ~]# find / -name nginx.conf

/usr/local/nginx/conf/nginx.conf

/usr/local/nginx/conf/beifen/nginx.conf

/root/nginx-1.13.1/conf/nginx.conf

# nginx配置文件所在地

[root@VM_0_3_centos ~]# cd /usr/local/nginx/conf/

[root@VM_0_3_centos conf]# ls

beifen koi-utf nginx.conf.default vhost

fastcgi.conf koi-win scgi_params win-utf

fastcgi.conf.default mime.types scgi_params.default

fastcgi_params mime.types.default uwsgi_params

fastcgi_params.default nginx.conf uwsgi_params.default

打开配置文件

[root@VM_0_3_centos conf]# vi nginx.conf

...

http{

...

#新增一句话 目录自定义

#nginx会自动执行一遍vhost目录下的所有配置文件 使之生效

include ./vhost/*.conf;

server {

...

}

...

}

...

进入自定义路径中添加配置文件

配置好 站点域名 网站运行的目录 网站运行的html

[root@VM_0_3_centos conf]# cd vhost/

[root@VM_0_3_centos vhost]# ls

nginx_fk.conf nginx_hctf.conf nginx_map.conf

[root@VM_0_3_centos vhost]# cat nginx_fk.conf

server {

listen 80; # 监听端口

server_name fk.creatorhy.com creatorhy.com; # 站点域名

root /usr/local/nginx/html/fangkuai/; # 站点根目录

index index.html index.htm index.php; # 默认导航页


location / {

# WordPress固定链接URL重写

if (!-e $request_filename) {

rewrite (.*) /index.php;

}

}


# PHP配置

location ~ \\.php$ {

fastcgi_pass unix:/var/run/php5-fpm.sock;

fastcgi_index index.php;

include fastcgi_params;

}

}

域名解析配好

linux下安装nginx


Nginx指令

[root@VM_0_3_centos ~]# cd /usr/local/nginx/sbin/

# nginx配置文件是否有错

[root@VM_0_3_centos sbin]# ./nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

# nginx重启服务

[root@VM_0_3_centos sbin]# ./nginx -s reload

到此已经配置好,可直接使用域名登录相应的项目


分享到:


相關文章: