With nginx/0.7.65 I'm getting this error on line 4. Why doesn't it recognize server
?
#### CHAT_FRONT ####
server {
listen 7000 default deferred;
server_name example.com;
root /home/deployer/apps/chat_front/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
#### CHAT_STORE ####
server {
listen 7002 default deferred;
server_name store.example.com;
root /home/deployer/apps/chat_store/current/public;
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
#### LOGIN ####
server {
listen 7004 default deferred;
server_name login.example.com;
root /home/deployer/apps/login/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
#### PERMISSIONS ####
server {
listen 7006 default deferred;
server_name permissions.example.com;
root /home/deployer/apps/permissions/current/public;
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
#### SEARCH ####
server {
listen 7008 default deferred;
server_name search.example.com;
root /home/deployer/apps/search/current/public;
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
#### ANALYTICS ####
server {
listen 7010 default deferred;
server_name analytics.example.com;
root /home/deployer/apps/analytics/current/public;
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
The server
directive must be contained in the context of http
module. Additionally you are missing top-level events module, which has one obligatory setting, and a bunch of stanzas which are to be in the http module of your config. While nginx documentation is not particularly helpful on creating config from scratch, there are working examples there.
Source: nginx documentation on server directive
Adding a top level entry got around the problem:
events { }
Try to adjust line endings and the encoding of your configuration file. In my case ANSI encoding and possibly "Linux style" line endings (only LF
symbols, not both CR
and LF
symbols) were required.
I know it is a rather old question. However the recommendation of the accepted answer (that the server
directive must be contained in the context of http
module) might confuse because there are a lot of examples (on the Nginx website also and in this Microsoft guide) where the server
directive is not contained in the context of http
module.
Possibly the answer of sd z ("I rewrote the *.conf file and it worked") comes from the same reason: there was a .config file with incorrect encoding or line endings which was corrected after the file has been rewrited.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With