當前位置:首頁 » 城管服務 » nginx伺服器配置

nginx伺服器配置

發布時間: 2020-12-09 17:26:54

❶ 怎麼給服務器配置nginx環境

最簡單的辦法,安裝護衛神.nginx大師,一鍵配置nginx+php+mysql+ftp

❷ 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。

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

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

❹ nginx配置前端,需要幾台什麼樣的伺服器。什麼樣的系統,什麼樣的配置

兩種前端架構:
lvs -> nginx前端代理 -> squid緩存
lvs -> squid前端緩存 -> nginx中層代理

squid在前面的優點:
Squid作純代理比專較穩當
前端少一級代理,響應速度會快屬,出問題的可能性要小
功能有限,不會常被調整
容易為人接受,只是為了擴充功能而增加中層代理
一般的配置簡便,比如增加一個二級域名,只需配置一個指向。
增加的nginx可擴展功能,增加對應用服務的負載均衡等。

squid在前面的缺點:
squid支持的負載均衡配置復雜
容災問題
更新緩存要遍歷所有機器
squid只支持單cpu,所以浪費cpu

nginx在前面的優點:
分流、負載均衡功能強大,可以細致定義
可精細定製access_log
nginx的錯誤日誌更詳細
可讓squid只緩存無壓縮版本,由nginx壓縮,這樣可優化squid緩存容量
nginx可分擔部分無實時性要求的緩存

nginx在前面的優點:
nginx目前還有部分bug。
功能強,所以可能經常被調整
nginx代理用的短鏈接方式
單機上安裝nginx+squid的cpu消耗比純squid和純nginx之和要大一倍,但也不算高
容易遭到質疑,不易被接受。

❺ 如何將 Nginx 配置為Web伺服器

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

1
2
3
4
5

http {
server {
# Server configuration
}
}

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

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

1
2
3
4
5
6

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埠

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

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

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

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

❼ 如何在Nginx伺服器中設置多個站點

這里以配置2個站點(2個域名)為例,n 個站點可以相應增加調整,假設:
IP地址: *.*.*.*
域名1 example1.com 放在 /www/example1
域名2 example2.com 放在 /www/example2
配置 nginx virtual hosting 的基本思路和步驟如下:
把2個站點 example1.com, example2.com 放到 nginx 可以訪問的目錄 /www/
給每個站點分別創建一個 nginx 配置文件 example1.com.conf,example2.com.conf, 並把配置文件放到 /etc/nginx/vhosts/
然後在 /etc/nginx.conf 裡面加一句 include 把步驟2創建的配置文件全部包含進來(用 * 號)
重啟 nginx
具體過程
下面是具體的配置過程:

1、在 /etc/nginx 下創建 vhosts 目錄
mkdir /etc/nginx/vhosts

2、在 /etc/nginx/vhosts/ 里創建一個名字為 example1.com.conf 的文件,把以下內容拷進去
server {
listen 80;
server_name example1.com www. example1.com;

access_log /www/access_ example1.log main;

location / {
root /www/example1.com;
index index.php index.html index.htm;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/example1.com/$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}

3、在 /etc/nginx/vhosts/ 里創建一個名字為 example2.com.conf 的文件,把以下內容拷進去
server {
listen 80;
server_name example2.com www. example2.com;

access_log /www/access_ example1.log main;

location / {
root /www/example2.com;
index index.php index.html index.htm;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www/example2.com/$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.ht {
deny all;
}
}

4、打開 /etc/nginix.conf 文件,在相應位置加入 include 把以上2個文件包含進來
user nginx;
worker_processes 1;

# main server error log
error_log /var/log/nginx/error.log ;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

# main server config
http {
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"';

sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;

server {
listen 80;
server_name _;
access_log /var/log/nginx/access.log main;
server_name_in_redirect off;
location / {
root /usr/share/nginx/html;
index index.html;
}
}

# 包含所有的虛擬主機的配置文件
include /usr/local/etc/nginx/vhosts/*;
}

5、重啟 Nginx
/etc/init.d/nginx restart

❽ 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

❾ 一台伺服器上能部署2個nginx服務嗎

理論上是可以來的,通過安裝源不同的nginx到不同的位置
並且兩個nginx的配置文件中設置的監聽埠不能沖突
可以同時開啟多個nginx
但不建議這樣做,一般是通過server指令添加多個虛擬主機,而不是啟動多個nginx

❿ linux下如何配置nginx伺服器

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

僅作參考:

#運行用戶
usernobody;
#啟動進程,通常設置成和的數量相等
worker_processes1;

#全局錯誤日誌及PID文件
#error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;

#pidlogs/nginx.pid;

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

#單個後台workerprocess進程的最大並發鏈接數
worker_connections1024;

#並發總數是worker_processes和worker_connections的乘積
#即max_clients=worker_processes*worker_connections
#在設置了反向代理的情況下,max_clients=worker_processes*worker_connections/4為什麼
#為什麼上面反向代理要除以4,應該說是一個經驗值
#根據以上條件,正常情況下的NginxServer可以應付的最大連接數為: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-SHn65535

}


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

access_loglogs/access.logmain;

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

#連接超時時間
#keepalive_timeout0;
keepalive_timeout65;
tcp_nodelayon;

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

#設定請求緩沖
client_header_buffer_size128k;
large_client_header_buffers4128k;


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

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

#設定本虛擬主機的訪問日誌
access_loglogs/nginx.access.logmain;

#默認請求
location/{

#定義首頁索引文件的名稱
indexindex.phpindex.htmlindex.htm;

}

#定義錯誤提示頁面
error_page500502503504/50x.html;
location=/50x.html{
}

#靜態文件,nginx自己處理
location~^/(images|javascript|js|css|flash|media|static)/{

#過期30天,靜態文件不怎麼更新,過期可以設大一點,
#如果頻繁更新,則可以設置得小一點。
expires30d;
}

#PHP腳本請求全部轉發到FastCGI處理.使用FastCGI默認配置.
location~.php${
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
includefastcgi_params;
}

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

}
}
熱點內容
影視轉載限制分鍾 發布:2024-08-19 09:13:14 瀏覽:319
韓國電影傷口上紋身找心裡輔導 發布:2024-08-19 09:07:27 瀏覽:156
韓國電影集合3小時 發布:2024-08-19 08:36:11 瀏覽:783
有母乳場景的電影 發布:2024-08-19 08:32:55 瀏覽:451
我准備再看一場電影英語 發布:2024-08-19 08:14:08 瀏覽:996
奧迪a8電影叫什麼三個女救人 發布:2024-08-19 07:56:14 瀏覽:513
邱淑芬風月片全部 發布:2024-08-19 07:53:22 瀏覽:341
善良媽媽的朋友李采潭 發布:2024-08-19 07:33:09 瀏覽:760
哪裡還可以看查理九世 發布:2024-08-19 07:29:07 瀏覽:143
看電影需要多少幀數 發布:2024-08-19 07:23:14 瀏覽:121