cat ~/nginx/conf/nginx.conf
# 配置使用的用戶
#user nobody;
#配置工作線程數
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
# 配置併發連接數
events {
worker_connections 1024;
}
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"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# 配置虛擬主機
server {
# 配置監聽端口和服務名稱(服務名可以IP或域名,比如www.baidu.com)
listen 8386;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#配置html位置
location / {
# root代表html文件的根目錄,index爲主頁文件(沒有/代表爲相對root的路徑)
root htmlyves;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
單個虛擬主機配置說明:
server {
# 監聽端口
listen 8387;
# 服務名稱(IP或域名)
server_name yveshe.com;
# 位置配置,/指代的是nginx的安裝目錄,說明配置root和index的時候如果配置的不是絕對路徑,則默認在nginx的安裝目錄下查找
location / {
#配置根目錄
root 8387;
# 配置主頁
index index.html index.htm;
}
# 配置接受請求的日誌保存文件和保存的日誌的格式,日誌格式main需要在前面定義,也可以自己定義
access_log logs/access_8387.log main;
}