nginx多站点配置

怼烎@ 2022-08-10 10:59 331阅读 0赞

一:nginx.conf 主文件配置(/opt/nginx/conf/nginx.conf)

user www www;

worker_processes 4;
worker_cpu_affinity 0001 0010 0100 1000;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

pid logs/nginx.pid;
#google_perftools_profiles /tmp/tcmalloc;
events {
use epoll;
worker_connections 65535;
}

http {
include mime.types;
default_type application/octet-stream;

  1. \#log\_format main '$remote\_addr - $remote\_user \[$time\_local\] "$request" '
  2. \# '$status $body\_bytes\_sent "$http\_referer" '
  3. \# '"$http\_user\_agent" "$http\_x\_forwarded\_for"';
  4. \#access\_log logs/access.log main;
  5. server\_names\_hash\_bucket\_size 128;
  6. client\_header\_buffer\_size 32k;
  7. large\_client\_header\_buffers 4 32k;
  8. client\_max\_body\_size 300m;
  9. sendfile on;
  10. tcp\_nopush on;
  11. fastcgi\_connect\_timeout 300;
  12. fastcgi\_send\_timeout 300;
  13. fastcgi\_read\_timeout 300;
  14. fastcgi\_buffer\_size 64k;
  15. fastcgi\_buffers 4 64k;
  16. fastcgi\_busy\_buffers\_size 128k;
  17. fastcgi\_temp\_file\_write\_size 128k;
  18. \#keepalive\_timeout 0;
  19. keepalive\_timeout 60;
  20. tcp\_nodelay on;
  21. server\_tokens off;
  22. gzip on;
  23. gzip\_min\_length 1k;
  24. gzip\_buffers 4 16k;
  25. gzip\_http\_version 1.1;
  26. gzip\_comp\_level 2;
  27. gzip\_types text/plain application/x-javascript text/css application/xml;
  28. gzip\_vary on;
  29. server
  30. \{
  31. listen 80;
  32. server\_name \_;
  33. charset utf-8;
  34. \#include rewrite.conf;
  35. index index.php index.html index.htm;
  36. server\_name\_in\_redirect off;
  37. \#root /var/www/;
  38. \#location ~ .\*\\.(php|php5)?$
  39. \# \{
  40. \# fastcgi\_pass unix:/tmp/php-cgi.sock;
  41. \# fastcgi\_index index.php;
  42. \# include fcgi.conf;
  43. \# \}
  44. \# location /status \{
  45. \# stub\_status on;
  46. \# access\_log off;
  47. \# \}
  48. \# location ~ .\*\\.(gif|jpg|jpeg|png|bmp|swf)$
  49. \# \{
  50. \# expires 30d;
  51. \# \}
  52. \# location ~ .\*\\.(js|css)?$
  53. \# \{
  54. \# expires 12h;
  55. \# \}
  56. \# access\_log off;
  57. \}

include /usr/local/nginx/conf/vhost/*.conf;

}

二:nginx_site.conf(/opt/nginx/conf/vhost/nginx_site.conf)

server{
listen 80;
server_name www.88888888.com 88888888.com;
#include rewrite.conf;
#charset utf-8;
root /var/www/site;
index index.php index.html index.htm;

location ~ .*\.(php|php5)?$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
#root /var/www/site;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /var/www/site$fastcgi_script_name;
# include fastcgi_params;
}

location /status {
stub_status on;
access_log off;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}

location ~ .*\.(js|css)?$ {
expires 12h;
}

  1. access\_log off;
  2. location ~ /\\.ht \{

deny all;
}
}

三:nginx_fly.conf(/opt/nginx/conf/vhost/nginx_fly.conf)

server{
listen 80;
server_name fly.88888888.com;
#include rewrite.conf;
#charset utf-8;
root /var/www/union;
index index.php index.html index.htm;

location ~ .*\.(php|php5)?$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;

# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /var/www/site$fastcgi_script_name;
# include fastcgi_params;
}

location /status {
stub_status on;
access_log off;
}

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}

location ~ .*\.(js|css)?$ {
expires 12h;
}

  1. access\_log off;
  2. location ~ /\\.ht \{

deny all;
}
}

发表评论

表情:
评论列表 (有 0 条评论,331人围观)

还没有评论,来说两句吧...

相关阅读

    相关 nginx配置站点密码访问办法

    阿里云上面放了个nginx,但是不希望别人访问,除了吧url搞得非常长并且奇怪(这样只有你告诉别人才知道地址。。。) 环境:Ubuntu linux下都差不多,可能某些

    相关 Nginx配置站点

    有时候你想在一台服务器上为不同的域名运行不同的站点。比如www.siteA.com作为博客,www.siteB.com作为论坛。你可以把两个域名的IP都解析到你的服务器上,但是