首页 > 系统相关 >docker安装nginx配置

docker安装nginx配置

时间:2022-10-27 11:35:01浏览次数:62  
标签:index com local nginx usr docker 安装 fastcgi

编译安装nginx的配置文件的路径在哪
这个版本不同,位置还是不同的。
我的是nginx-1.9.9版本源码安装,配置文件在conf这个目录里面:
/usr/local/nginx/conf/nginx.conf
如果你找不见也可以搜索:
find/|grepnginx.conf
php和nginx安装后怎么配置
先安装编译依赖的一些组件
复制代码代码如下:
yuminstallpcrepcre-developensslopenssl-devel-y
1、解压程序包
复制代码代码如下:
tarxfnginx-1.10.0.tar.gz
cdnginx-1.10.0
2、预编译配置参数
复制代码代码如下:
./configure--user=www\
--group=www\
--prefix=/data/server/nginx\
--with-http_stub_status_module\
--without-http-cache\
--with-http_ssl_module\
--with-http_gzip_static_module
3、执行编译
复制代码代码如下:
make&&makeinstall
4、替换配置文件
nginx.conf
userwwwwww;
worker_processes1;
error_log/u01/data/log/nginx/error.logcrit;
pid/u01/data/server/nginx/logs/nginx.pid;
#Specifiesthevalueformaximumfiledescriptorsthatcanbeopenedbythisprocess.
worker_rlimit_nofile65535;
events
useepoll;
worker_connections65535;
http{
includemime.types;
default_typeapplication/octet-stream;
#charsetgb2312;
server_names_hash_bucket_size128;
client_header_buffer_size32k;
large_client_header_buffers432k;
client_max_body_size8m;
sendfileon;
tcp_nopushon;
keepalive_timeout60;
tcp_nodelayon;
fastcgi_connect_timeout300;
fastcgi_send_timeout300;
fastcgi_read_timeout300;
fastcgi_buffer_size64k;
fastcgi_buffers464k;
fastcgi_busy_buffers_size128k;
fastcgi_temp_file_write_size128k;
gzipon;
gzip_min_length1k;
gzip_buffers416k;
gzip_http_version1.0;
gzip_comp_level2;
gzip_typestext/plainapplication/x-javascripttext/cssapplication/xml;
gzip_varyon;
#limit_zonecrawler$binary_remote_addr10m;
log_formatmain'$remote_addr-"$request_time"[$time_local]"$request"'
'"$status"$body_bytes_sent"$http_referer"'
'"$http_user_agent"$http_x_forwarded_for';
log_format'$remote_addr-$remote_user[$time_local]"$request"'
'$status$body_bytes_sent"$http_referer"'
'"$http_user_agent"$http_x_forwarded_for"$request_time"';
include/u01/alidata/server/nginx/conf/vhosts/*.conf;
本回答由提问者推荐
nginx如何配置静态文件expires时间?
minfresh指示客户机可以接收响应时间小于当前时间加上指定时间的响应
nginx修改配置需要重启吗
nginx更改配置文件后需要重启生效。1、更改配置重启nginx:kill-HUP主进程号或进程号文件路径或者使用cd/usr/local/nginx/sbin./nginx-sreload2、判断配置文件是否正确:nginx-t-c/usr/local/nginx/conf/nginx.conf或者cd/usr/local/nginx/sbin./nginx-t
window下Nginx怎么安装启动
Nginx有那么多有点,当然要试下了,window环境下,Nginx怎么安装启动呢?
A)把下载的window下的安装包,解压到一个不包含空格的路径下,比如:d:/Nginx
B)打开命令行窗口【win+R 输入cmd,然后确定】
C)进入解压目录【cd /d D:/Nginx】
D)输入:start nginx ,然后回车,开始运行Nginx
运行之后,怎么关闭呢,Nginx -s stop,即可。还有其他选项供选择:
Nginx -s[stop|quit|reopen|reload]
Nginx -s stop快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。
Nginx -s quit平稳关闭Nginx,保存相关信息,有安排的结束web服务。
Nginx -s reload因改变了Nginx相关配置,需要重新加载配置而重载。
Nginx -s reopen重新打开日志文件。
.window环境下,nginx安装启动的步骤如下:
1. 把下载的window下的安装包,解压到一个不包含空格的路径下,比如:d:/nginx
2. 打开命令行窗口【win+r 输入cmd,然后确定】。
3. 进入解压目录【cd /d d:/nginx】。
4. 输入:start nginx ,然后回车,开始运行nginx。
5. 运行之后,可执行nginx -s stop 关闭nginx。
nginx还有其他选项供选择:
nginx -s[stop|quit|reopen|reload]
nginx -s stop快速关闭nginx,可能不保存相关信息,并迅速终止web服务。
nginx -s quit平稳关闭nginx,保存相关信息,有安排的结束web服务。
nginx -s reload因改变了nginx相关配置,需要重新加载配置而重载。
nginx -s reopen重新打开日志文件。
Nginx 域名配置
1、直接IP访问
2、建立一个内网的dns服务器方法一:多个.conf方法(优点是灵活,缺点就是站点比较多配置起来麻烦)
这里以配置2个站点(2个域名)为例,n 个站点可以相应增加调整,假设:
ip地址: 192.168.1.100
域名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, 并把配置文件放到 /usr/local/nginx/vhosts/
然后在 /usr/local/nginx/nginx.conf 里面加一句 include 把步骤2创建的配置文件全部包含进来(用 * 号)
重启 nginx
1、打开 /usr/local/nginx/nginix.conf 文件,在相应位置加入 include 把以上2个文件包含进来
user www www;
worker_processes 1;
# main server error log
error_log/usr/local/nginx/log/nginx/error.log ;
pid/usr/local/nginx/nginx.pid;
events {
worker_connections 51200;
# main server config
http {
includemime.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”‘;
sendfileon;
#tcp_nopushon;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen80;
server_name_;
access_log/usr/local/nginx/log/nginx/access.log main;
server_name_in_redirect off;
location / {
root /usr/share/nginx/html;
index index.html;
# 包含所有的虚拟主机的配置文件
include /usr/local/nginx/vhosts/*;
2、在 /usr/local/nginx 下创建 vhosts 目录
mkdir /usr/local/nginx/vhosts
3、在 /usr/local/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_page500 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_pass127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param script_filename /www/example1.com/$fastcgi_script_name;
includefastcgi_params;
}
location ~ /.ht {
deny all;
}
3、在 /usr/local/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_page500 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_pass127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param script_filename /www/example2.com/$fastcgi_script_name;
includefastcgi_params;
}
location ~ /.ht {
deny all;
}
5、重启 nginx
/etc/init.d/nginx restart
方法二:动态目录方法(优点是方便,每个域名对应一个文件夹,缺点是不灵活)
这个简单的方法比起为每一个域名建立一个 vhost.conf 配置文件来讲,只需要在现有的配置文件中增加如下内容:
# replace this port with the right one for your requirements
# 根据你的需求改变此端口
listen80; #could also be 1.2.3.4:80 也可以是1.2.3.4:80的形式
# multiple hostnames seperated by spaces. replace these as well.
# 多个主机名可以用空格隔开,当然这个信息也是需要按照你的需求而改变的。
server_name star.yourdomain.com *.yourdomain.com *.yourdomain.com/;
#alternately: _ *
#或者可以使用:_ * (具体内容参见本维基其他页面)
root /path/to/webroot/$host;
error_page 404;
access_log logs/star.yourdomain.com.access.log;
location / {
root/path/to/webroot/$host/;
index index.php;
# serve static files directly
# 直接支持静态文件 (从配置上看来不是直接支持啊)
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_logoff;
expires30d;
location ~ .php$ {
# by all means use a different server for the fcgi processes if you need to
# 如果需要,你可以为不同的fcgi进程设置不同的服务信息
fastcgi_pass127.0.0.1:yourfcgiporthere;
fastcgi_index index.php;
fastcgi_param script_filename /path/to/webroot/$host/$fastcgi_script_name;
fastcgi_param query_string$query_string;
fastcgi_param request_method$request_method;
fastcgi_param content_type$content_type;
fastcgi_param content_length$content_length;
fastcgi_intercept_errors on;
location ~ /.ht {
deny all;
最后附另外一个二级域名匹配的方法
server_name *.abcd.com;
获取主机名
if ( $host ~* (.*).(.*).(.*))
set $domain $1;
root html/abc/$domain/;
location /
root html/abcd/$domain;
index index.html index.php;

标签:index,com,local,nginx,usr,docker,安装,fastcgi
From: https://blog.51cto.com/yetaotao/5800571

相关文章

  • nginx没有权限
    nginx.conf配置的root目录要什么权限你可以修改nginx配置里的root,比如下面的代码路径是到/data/www读取:server{listen80;server_nametest.abc.com;root/data/www;indexindex......
  • nginx安装配置 linux
    编译安装nginx的配置文件的路径在哪这个版本不同,位置还是不同的。我的是nginx-1.9.9版本源码安装,配置文件在conf这个目录里面:/usr/local/nginx/conf/nginx.conf如果你找不见......
  • nginx配置文件location详解
    Centos7安装nginx完成后发现nginx.conf文件中没有server,只有events{...}和http{...},这是什么问题?在nginx.conf文件同目录的conf.d文件夹下的default.conf文件里面,应该是新......
  • nginx安装反向代理
    centos使用yum安装nginx后如何添加模块1.确认你已经安装在用的nginx信息nginx-V2.下载和此版本相同的nginx源码包并解压tar-xvzfnginx-1.10.3.tar.gz3.更新一下依赖相关包y......
  • nginx安装rewrite模块
    Linuxnginx安装目录找不到?如果找不到,那应该就是没有完成安装或者编译:首先要确认是否正确安装了:make&&makeinstall重新编译一次其次,在确定安装的目录:直接查看rpm包试试,rpm-q......
  • nginx处理一个请求的过程
    nginx能不能把一个请求过来的get参数接受,然后作为参数转发到另一个地址?php端用__GET()获取参数,然后用libcurl库函数转发至另一个URL地址。nginx如何拦截请求可以设置拦截一......
  • nginx错误日志路径
    nginx500错误,怎么解决(1)查看nginxerrorlog,查看phperrorlog(2)如果是toomanyopenfiles,修改nginx的worker_rlimit_nofile参数,使用ulimit查看系统打开文件限制,修改/etc/secur......
  • nginxyum下来的安装包默认再哪个目录
    linuxnginx缓存文件在哪个文件夹假设你是用包管理工具安装的nginx:如果你是redhat系列的,安装包是.rpm包,或者你用yum安装的话,这样查找:rpm-qlnginx如果是ubuntu,也是类似的方......
  • Linux下Jdk1.8的安装与环境变量配置教程(添加完整配置)
    文章目录摘要1.1常见概念1.1.1机器学习本质1.1.2什么是神经网络1.1.3各种常见算法图示1.1.4计算图的导数计算1.1.5理解局部最优与全局最优1.1.6大数据与深度学习......
  • LinuxCentOS在不删除Linux自带JDK的情况下安装JDK1.8(图文教程:重点是环境变量的配置)...
    环境:CentOS6.9安装JAVAJDK1.81.创建两个文件夹?mkdir-p/export/softmkdir/export/servers2.?上传jdk安装包到?/export/soft?命令:rz?选择JDK......