我刚刚选择 nginx 作为我的网络服务器,并且我确实遵循了本教程:https://github.com/groovemonkey/hands_on_linux-self_hosted_wordpress_for_linux_beginners
但是,我无法连接到我的网络服务器。
当我这样做时,$ sudo nginx
我得到以下回复:
nginx: [warn] duplicate MIME type "text/html" in /etc/nginx/nginx.conf:34
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
$ sudo netstat -plten | grep 80
给出以下结果:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 70851 9943/nginx -g daemo
tcp6 0 0 :::80 :::* LISTEN 0 70850 9943/nginx -g daemo
这是我的 nginx.conf:
user www-data;
worker_processes auto;
pid /run/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"';
error_log /var/log/nginx_error.log error;
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
# SSL
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # no sslv3 (poodle etc.)
ssl_prefer_server_ciphers on;
# Gzip Settings
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_min_length 512;
gzip_types text/plain text/html application/x-javascript text/javascript application/javascript text/xml text/css application/font-sfnt;
fastcgi_cache_path /usr/share/nginx/cache/fcgi levels=1:2 keys_zone=microcache:10m max_size=1024m inactive=1h;
include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
}
这是我的 site.conf (位于 /etc/nginx/conf.d/ 中):
server {
listen [::]:80;
server_name _;
client_max_body_size 20m;
index index.php index.html index.htm;
root /home/tutorialinux/public_html;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# pass the PHP scripts to FastCGI server
location ~ \.php$ {
# Basic
try_files $uri =404;
fastcgi_index index.php;
# Create a no cache flag
set $no_cache "";
# Don't ever cache POSTs
if ($request_method = POST) {
set $no_cache 1;
}
# Admin stuff should not be cached
if ($request_uri ~* "/(wp-admin/|wp-login.php)") {
set $no_cache 1;
}
# WooCommerce stuff should not be cached
if ($request_uri ~* "/store.*|/cart.*|/my-account.*|/checkout.*|/addons.*") {
set $no_cache 1;
}
# If we are the admin, make sure nothing
# gets cached, so no weird stuff will happen
if ($http_cookie ~* "wordpress_logged_in_") {
set $no_cache 1;
}
# Cache and cache bypass handling
fastcgi_no_cache $no_cache;
fastcgi_cache_bypass $no_cache;
fastcgi_cache microcache;
fastcgi_cache_key $scheme$request_method$server_name$request_uri$args;
fastcgi_cache_valid 200 60m;
fastcgi_cache_valid 404 10m;
fastcgi_cache_use_stale updating;
# General FastCGI handling
fastcgi_pass unix:/var/run/php/tutorialinux.sock;
fastcgi_pass_header Set-Cookie;
fastcgi_pass_header Cookie;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_intercept_errors on;
include fastcgi_params;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff|ttf|svg|otf)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
access_log off;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
server {
listen 80;
server_name snapecraft.ddns.net;
rewrite ^/(.*)$ http://www.snapecraft.ddns.net/$1 permanent;
}
系统是Linux Mint 18.3 Sylvia。
编辑1:
现在 nginx 能够绑定端口(忘记替换 default.conf),但我仍然收到 Connection Refused 的消息。这与 PHP/FastCGI 有关吗?
答案1
只需尝试终止或终止现有的 nginx 进程即可。并重新开始。现在您已经有了以守护进程模式运行的 nginx 进程。并且这个进程阻塞了80端口。