騰訊雲服務安裝nginx

1.安裝依賴,如果已經安裝了依賴,則跳過

yum -y install gcc gcc-c++ wget net-tools pcre-devel zlib-devel openssl-devel

2.下載並解壓安裝包

#進入常用文件夾
cd /usr/local/src/

#下載源碼
wget http://nginx.org/download/nginx-1.7.12.tar.gz

#解壓
tar zxvf nginx-1.7.12.tar.gz

#進入目錄
cd nginx-1.7.12

3.安裝

./configure --prefix=/usr/local/nginx

在這部會出現一些錯誤,一些錯誤解決方法如下:

 ./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

 安裝pcre-devel解決問題   : yum -y install pcre-devel 

./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using –without-http_gzip_module
option, or install the zlib library into the system, or build the zlib 
library statically from the source with nginx by using –with-zlib=<path> option.

則需要安裝“zlib-devel”即可 : yum install -y zlib-devel 

4.繼續安裝

#編輯   

make

#查看是否有錯誤  

echo $?    //顯示0則成功 其他數組則失敗

#安裝

make install

5.啓動

# 查看 Nginx 版本
nginx -v
# 查看 Nginx 安裝目錄
rpm -ql nginx
# 啓動 Nginx
service nginx start

# 重啓 Nginx
service nginx restart

6.配置項目

server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
       # root         /usr/share/nginx/html/web;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        #配置靜態圖片訪問地址 

         location   /images {  //圖片訪問前綴
             alias  /usr/share/nginx/html/server/images/;  //圖片存放路徑
             autoindex on;
        }

        location   / {   
              root  /usr/share/nginx/html/web;  //項目存放路徑
              index index.html;
        } 

當項目爲單頁面時,瀏覽器刷新後報404,下面是解決辦法:

location / {
            root   /mydata/transfer/html/helper/dist;
            index  index.html index.htm;
            try_files  $uri $uri/ /index.html;
        }

 7.查看項目

 

注意:可能在訪問圖像的時候會寶禁止訪問錯誤‘forbid’問題,這時候要對圖像的存放文件夾修改訪問權限

#進入圖像存放文件夾

cd  xx/xx/xx/ 

# 修改訪問權限,加入-R 參數,就可以將讀寫權限傳遞給子文件夾,講解權限操作的博客文章:https://blog.csdn.net/u013197629/article/details/73608613可以參考下。

chmod -R 777  /usr/share/nginx/html/server/images

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章