要配置 Nginx 来处理 PHP 应用程序,可以创建一个投入的下的conf文件sites-available
,然后在下面创建相应的符号链接sites-enabled
,但我不想使用这种方法 - 我更喜欢一种方法全球的conf 用于运行 php 脚本,适用于所有项目。可以放在里面的东西nginx.conf
。我没有在任何地方找到这样的全局 conf。
是否有用于运行 php 脚本的 Nginx 全局配置?
答案1
类似这样。你只需要将你的项目保存在与它的域名 ($host) 对应的文件夹中即可。检查 nginx 变量: http://nginx.org/en/docs/http/ngx_http_core_module.html#var_host
user www-data;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 8192;
}
http {
server_tokens off;
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
#gzip on;
server {
listen 80 default_server;
root /var/www/$host;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires 24h;
log_not_found off;
}
location ~ /\. { access_log off; log_not_found off; deny all; }
rewrite /files/$ /index.php last;
if ($uri !~ wp-content/plugins) {
rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
}
location ~ \.php$ {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
client_max_body_size 25M;
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}
}