導航:首頁 > IDC知識 > nginx下載伺服器配置

nginx下載伺服器配置

發布時間:2020-11-01 16:53:52

1、如何把伺服器的nginx配置設置為

1.網站路徑
查看一下待會需要設置的網站的路徑,pwd確認 /var/www/wwwroot

2
1.Ngix配置文件
本例是u-mail linux一體盤的nginx路徑,其他根據實內際情況的路容徑替換

3
3. Apahce配置文件2個
Apache的配置文件也在apache路徑下面,有httpd.config 和vhosts.conf

2、如何在linux下搭建nginx伺服器

1、下載後解壓nginx

tar -zxvf nginx-1.4.7.tar.gz
2、安裝gcc等依賴包
yum -y install gcc pcre-devel openssl openssl-devel
3、開始安裝nginx
cd進入nginx-1.4.7目錄內
./configure 編譯
make&&make install 這一步需要先cd出來嗎?在裡面會安裝失敗嗎?我忘了 = =
4、此時就已經安裝完成,默認安裝在了/usr/local/nginx/sbin/nginx
5、啟動
命令行輸入/usr/local/nginx/sbin/nginx,沒反應
輸入ps -ef | grep nginx查看nginx進程
6、測試
命令行輸入 curl http://127.0.0.1
會出現welcome to nginx之類的就說明對了!
7、加入到環境變數
vim /etc/profile
尾行添加
PATH=$PATH:/usr/local/nginx/sbin
export PATH
保存關閉後運行 source /etc/profile 即會加入環境變數
8、常用命令
[root@ usr]# nginx -s stop停止nginx
[root@ usr]# nginx 運行nginx
[root@ usr]# nginx -s reload 重啟nginx
[root@ usr]# nginx -t 測試nginx
9、防火牆允許外網訪問
vim /etc/sysconfig/iptables
添加過濾規則
-A -INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
好像是保存後即時生效把?
service iptables stop
service iptables start
重啟服務後還是會生效,親測
10、修改網站默認根目錄路徑
網站默認根目錄放在/usr/local/nginx/html
命令行輸入 vim /usr/local/nginx/conf/nginx.conf
找到改為
server {
listen 80;
server_name localhost;
root /var/www/html/default;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root html;
index index.html index.htm;
}
注釋掉下面的,在上面添加自己想要的根目錄,重啟nginx才能生效。

3、請問我的nginx伺服器無法下載中文路徑的文件,怎麼辦?謝謝!

一般linux中使用utf-8編碼,niginx中也是如此,如果不是則都配置為utf-8編碼,然後在你的代碼邏輯中設置下載文件名稱時進行編碼即可,java代碼類似:
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("文件名", "utf-8"));
response.setHeader("X-Accel-Redirect", "/down/" + URLEncoder.encode("文件名路徑", "utf-8"));

4、linux下怎麼查看伺服器的nginx配置文件

當你執行 nginx -t 得時候,nginx會去測試你得配置文件得語法,並告訴你配置文件是否寫得正確,同時也告訴了你配置文件得路徑:

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

首先執行命令找到nginx路徑
ps aux | grep nginx
如nginx路徑為
/usr/local/nginx/sbin/nginx

然後執行以下命令
/usr/local/nginx/sbin/nginx -V
默認放在 安裝目錄下 conf/nginx.conf

5、nginx 搭建多少台web伺服器

設置虛擬伺服器
listen:
Nginx 配置文件至少包含一個 server 命令 ,用來定義虛擬伺服器。當請求到來時, Nginx 會首先選擇一個虛擬伺服器來處理該請求。
虛擬伺服器定義在 http 上下文中的 server 中:

http {
server {
# Server configuration
}
}

注意: http 中可以定義多個 server

server 配置塊使用 listen 命令監聽本機 IP 和埠號(包括 Unix domain socket and path),支持 IPv4、IPv6,IPv6地址需要用方括弧括起來:

server {
listen 127.0.0.1:8080; # IPv4地址,8080埠
# listen [2001:3CA1:10F:1A:121B:0:0:10]:80; # IPv6地址,80埠
# listen [::]:80; # 聽本機的所有IPv4與IPv6地址,80埠
# The rest of server configuration
}

上述配置,如果不寫埠號,默認使用80埠,如果不寫 IP ,則監聽本機所有 IP。

6、Nginx Web伺服器成功安裝和工作,需要進一步配置,那要怎麼配置呀?

建議安裝護衛神.nginx大師,可以一步安裝nginx+php+mysql+ftp,還能在線開設網站

7、怎麼配置tp在nginx伺服器下

安裝
ubuntu下
sudo apt-get install nginx

啟動

sudo /etc/init.d/nginx start #通過init.d下的啟動文件啟動。
sudo service nginx start#通過ubuntu的服務管理器啟動

配置文件位置

/etc/nginx/nginx.conf

編譯安裝
1.先決條件
(1).gcc

apt-get install gcc

(2).pcre(Perl Compatible Regular Expression)

apt-get install libpcre3 libpcre3-dev

(3).zlib
apt-get install zliblg zliblg-dev

(4).openssl
apt-get install openssl opensll-dev

#如果非apt,可以使用下載包手動編譯安裝的方式處理

2.下載包 下載穩定版

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

3.解壓安裝
tar -xzvf nginx-1.4.4.tar.gz
#默認,安裝目錄/usr/local/nginx
./configure
make
make install

#配置
./configure --conf-path=/etc/nginx/nginx.conf

可以配置一些其他選項
安裝後查看下目錄下的Configuration summary
4.init腳本
需要給nginx建立一個init腳本
從網上撈一個,放入/etc/init.d/nginx
推薦編譯配置

8、linux下如何配置nginx伺服器

百度nginx,就有很多配置安裝技巧了。問題的涉及范圍太廣了,不好回答。

僅作參考:

#運行用戶
user nobody;
#啟動進程,通常設置成和cpu的數量相等
worker_processes  1;

#全局錯誤日誌及PID文件
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

#工作模式及連接數上限
events {
    #epoll是多路復用IO(I/O Multiplexing)中的一種方式,
    #僅用於linux2.6以上內核,可以大大提高nginx的性能
    use   epoll; 

    #單個後台worker process進程的最大並發鏈接數    
    worker_connections  1024;

    # 並發總數是 worker_processes 和 worker_connections 的乘積
    # 即 max_clients = worker_processes * worker_connections
    # 在設置了反向代理的情況下,max_clients = worker_processes * worker_connections / 4  為什麼
    # 為什麼上面反向代理要除以4,應該說是一個經驗值
    # 根據以上條件,正常情況下的Nginx Server可以應付的最大連接數為:4 * 8000 = 32000
    # worker_connections 值的設置跟物理內存大小有關
    # 因為並發受IO約束,max_clients的值須小於系統可以打開的最大文件數
    # 而系統可以打開的最大文件數和內存大小成正比,一般1GB內存的機器上可以打開的文件數大約是10萬左右
    # 我們來看看360M內存的VPS可以打開的文件句柄數是多少:
    # $ cat /proc/sys/fs/file-max
    # 輸出 34336
    # 32000 < 34336,即並發連接總數小於系統可以打開的文件句柄總數,這樣就在操作系統可以承受的范圍之內
    # 所以,worker_connections 的值需根據 worker_processes 進程數目和系統可以打開的最大文件總數進行適當地進行設置
    # 使得並發總數小於操作系統可以打開的最大文件數目
    # 其實質也就是根據主機的物理CPU和內存進行配置
    # 當然,理論上的並發總數可能會和實際有所偏差,因為主機還有其他的工作進程需要消耗系統資源。
    # ulimit -SHn 65535

}


http {
    #設定mime類型,類型由mime.type文件定義
    include    mime.types;
    default_type  application/octet-stream;
    #設定日誌格式
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    #sendfile 指令指定 nginx 是否調用 sendfile 函數(zero copy 方式)來輸出文件,
    #對於普通應用,必須設為 on,
    #如果用來進行下載等應用磁碟IO重負載應用,可設置為 off,
    #以平衡磁碟與網路I/O處理速度,降低系統的uptime.
    sendfile     on;
    #tcp_nopush     on;

    #連接超時時間
    #keepalive_timeout  0;
    keepalive_timeout  65;
    tcp_nodelay     on;

    #開啟gzip壓縮
    gzip  on;
    gzip_disable "MSIE [1-6].";

    #設定請求緩沖
    client_header_buffer_size    128k;
    large_client_header_buffers  4 128k;


    #設定虛擬主機配置
    server {
        #偵聽80埠
        listen    80;
        #定義使用 www.zz04.com訪問
        server_name  www.zz04.com;

        #定義伺服器的默認網站根目錄位置
        root html;

        #設定本虛擬主機的訪問日誌
        access_log  logs/nginx.access.log  main;

        #默認請求
        location / {
            
            #定義首頁索引文件的名稱
            index index.php index.html index.htm;   

        }

        # 定義錯誤提示頁面
        error_page   500 502 503 504 /50x.html;
        location = /50x.html {
        }

        #靜態文件,nginx自己處理
        location ~ ^/(images|javascript|js|css|flash|media|static)/ {
            
            #過期30天,靜態文件不怎麼更新,過期可以設大一點,
            #如果頻繁更新,則可以設置得小一點。
            expires 30d;
        }

        #PHP 腳本請求全部轉發到 FastCGI處理. 使用FastCGI默認配置.
        location ~ .php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include fastcgi_params;
        }

        #禁止訪問 .htxxx 文件
            location ~ /.ht {
            deny all;
        }

    }
}

9、如何在linux下搭建nginx伺服器

1.先從nginx官網下載最新的版本 http://nginx.org/download/nginx-1.7.8.tar.gz 2.解壓nginx-1.7.8.tar.gz,然後執行下面專操作屬即可 ./configure --prefix=/usr/local/nginxmakemake install

與nginx下載伺服器配置相關的知識