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

到此已經配置好,可直接使用域名登錄相應的項目


分享到:


相關文章: